VB Script in an Outlook form

J

Jason

Hi, Please can you help,

I'm programmming in VBA in Access 2003 and I want to create an outlook2003
mailitem containing a hyperlink that calls some VBscript within the form.

I've got three problems:
1. Getting any script in the form to run
2 Getting VBA to create an instance of the form
3. Getting the hyperlink to call the script
************************************************************
Problem 1
Using Outlook I can create a custom form containing VBScript. On the
properties tab I ticked the 'Send Form Definition with item' box. Then I
published the form in the personal forms library. I can see my custom form in
outlook when I do New>Choose Form... I can create a new item from this and it
works. However, when I send it to myself and open the received form, the
Item_Open event does not run any more.
************************************************************
Problem 2
My other problem is to create the message in VBA. Here are my three attempts.
Attempt 1
Save the form as an .oft. Then
Set Itm = myOlApp.CreateItemFromTemplate("C:\MyForm.oft")
Itm.HTMLBody = "<b><a href='file://D:/Test.txt'>This is a
hyperlink</a></b>"
Itm.Display

Now the created item looks OK but has no script in it and the hyperlink
doesn't work.
************************************************************
Attempt 2
Set Itm = myOlApp.CreateItem(olMailItem)
Itm.MessageClass = "IPM.Note.MyForm"
Itm.HTMLBody = "<b><a href='file://D:/Test.txt'>This is a
hyperlink</a></b>"
Itm.Display

It didn't work - It took no notice of the MessageClass line and just created
a MailItem
************************************************************
Attempt 3
Set myOlApp = CreateObject("Outlook.Application")
Set objFolder = myOlApp.ActiveExplorer.CurrentFolder
Set Itm = objFolder.Items.Add("IPM.Note.MyForm")
Itm.HTMLBody = "<b><a href='file://D:/Test.txt'>This is a
hyperlink</a></b>"
Itm.Display

It worked on one PC but not another (just created a MailItem)
************************************************************
Problem 3
I've only got as far as an href hyperlink. How do I write a hyperlink that
calls a VBScript function within the form?

Any ideas?
Thanks
Jason
 
J

Ji Zhou

Hello Jason,

I cannot reproduce the first issue. In my test, I create a custom form and
add Item_Open behind codes, publish the form. And then I create an item from
the custom form template, send it to myself. In the local machine and
another test machine, I received the email. If I double click the receive
item to open it, I can see a message box pop up which indicates my VBScript
runs correctly.

As to the second issue, I write the following codes to achieve the
objective,
Sub Test()
Dim oInbox As MAPIFolder
Set oInbox = Application.Session.GetDefaultFolder(olFolderInbox)
Dim oItems As items
Set oItems = oInbox.items
Set omyform = oItems.Add("IPM.Note.MyForm")
omyform.HTMLBody = "<b><a href='file://D:/Test.txt'>This is a
hyperlink</a></b>"
omyform.Display
End Sub

The hyperlink looks OK and the Item_Open event executes. So the behind
VBScript codes work fine.

As to the third question, I do not think we can achieve something like that,
clicking a hyperlink to execute code behind vbscript.


Best regards,
Ji Zhou - MSFT
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top