Open Form Outlook 2000 VBA

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have created some email forms and added them to a new toolbar menu.

MyForms
Em_Repsonse1
Em_Response2

I want to add another menu item that automatically takes the current open
email and then takes the address in that email opens one of my forms with
that email address in it.

Can someone tell me how to open a form and possibly how to take the current
email in the top most email and put it into the To field of the new email

Regards
 
Try this macro - just change the message class to that of one of your custom
forms:

Sub LaunchCustomFormWithPrePopulatedRecipientAddress()
Dim objMail As Outlook.MailItem, objItem As Object
Dim objCustomMailForm As Outlook.MailItem

If ActiveInspector Is Nothing Then GoTo Leave:

Set objItem = ActiveInspector.CurrentItem
If objItem.Class <> olMail Then GoTo Leave:

Set objMail = ActiveInspector.CurrentItem
Set objCustomMailForm = Application.CreateItem(olMailItem)
objCustomMailForm.MessageClass = "IPM.Note.Test"
objCustomMailForm.To = objMail.SenderEmailAddress
objCustomMailForm.Display

Leave:
Set objMail = Nothing
Set objItem = Nothing
Set objCustomMailForm = Nothing
End Sub
 
Sorry, I forgot to mention that my code assumes that your custom form is
published in the Personal Forms library. Otherwise, use the
Items.Add("IPM.Note.CustomMessageClassName") method as you've done.

Note also that accessing the SenderEmailAddress is blocked in Outlook
2000/2002 - you'll have to accept the security dialog that pops up to get
access to this value (this link has full details:
http://www.outlookcode.com/d/sec.htm).

--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
Try Picture Attachments Wizard for Outlook! http://tinyurl.com/9bby8
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/
 
Thank you for your response.
I tried your code. It seems to fail on getting the current open message's
email address. I tried to comment out the
'objCustomMailForm.To = objMail.SenderEmailAddress
line to see what would happen and it opens a blank email message. Not my
form.

I also tried to add the address manually as shown below and it opens a blank
email address with the (e-mail address removed) in the To field. So this part works
sort of.

I have used a few other bits of code to VBA'ly open my forms and it works
fine.
Eg.
'--------Sues Code------------------------
Function Item_Open()
'OPENS A CUSTOM FORM from Sue M.
Set objFolder = Application.ActiveExplorer.CurrentFolder
Set objItem = _
objFolder.Items.Add("IPM.Note.Mymessage")
objItem.Display
Item_Open = False

End Function
'--------------------------------------------------------------------
The error message I get when I run your code is

Run-time error '438':
Object doesn't support this property or method

Any thoughts?

(Its getting late Friday I may pick this up again on Monday.)

Regards


'------------ YOUR CODE --Changed Slightly by me----------------
Sub LaunchCustomFormWithPrePopulatedRecipientAddress()
Dim objMail As Outlook.MailItem, objItem As Object
Dim objCustomMailForm As Outlook.MailItem

If ActiveInspector Is Nothing Then GoTo Leave:

Set objItem = ActiveInspector.CurrentItem
If objItem.Class <> olMail Then GoTo Leave:

Set objMail = ActiveInspector.CurrentItem
Set objCustomMailForm = Application.CreateItem(olMailItem)
objCustomMailForm.MessageClass = "IPM.Note.Mymessage"
'objCustomMailForm.To = objMail.SenderEmailAddress
objCustomMailForm.To = "(e-mail address removed)"
objCustomMailForm.Display

Leave:
Set objMail = Nothing
Set objItem = Nothing
Set objCustomMailForm = Nothing
End Sub
 
Thanks Eric.

I will take a look at it.

I was getting the nag screen with your code and just kept clicking it ok. I
will try playing with it again and re visit it on Monday.

Regards
Thanks.
 
Eric,

How would I use this code in Access? I am trying to open a custom form that
is stored in the Personal Forms Library using VBA. Your example looks like
it would work if in Outlook VBA, am I correct?
Also, how would I access the form from MS Access once I publish to the
Organizational Forms Library?

Thanks,
-mike
 
Back
Top