usa VBA to open an Outlook From

G

Guest

Please Help!

I would like to know the VBA code to open and Outlook form I created that is
in the Personal Forms Library.

I am currently using Access to send E-mail to people that are stored in my
database. I am using the code found in here
http://support.microsoft.com/kb/209948/en-us

I think I have to change one of the following lines of code to something
else that refers to the form.
-------------
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

'Create from Template
Set MyItem = myOlApp.CreateItemFromTemplate("C:\filename.oft")
------------

PS. The form is just a basic form letter that does not have any fields.
There are graphics on the form and that is why I need to use it instead of
creating a new mail message.

Thanks
 
S

Sue Mosher [MVP-Outlook]

To create a new instance of a custom form programmatically, use the Add method on the target folder's Items collection:

Set newItem = targetFolder.Items.Add("IPM.Post.YourFormName")

If it's a message form, use the Drafts folder as the target. If the target is a default folder, you can use the Namespace.GetDefaultFolder method to return it as a MAPIFolder object. To create an item in another person's mailbox, use Namespace.GetSharedDefaultFolder to get the MAPIFolder Otherwise, you can use the code at http://www.outlookcode.com/d/code/getfolder.htm to walk the folder hierarchy and return the MAPIFolder corresponding to a given path string.

See http://www.outlookcode.com/d/launchform.htm for other ideas.

Warning: YOu should not be using a published custom form for routine email messages to external recipients. An .oft file would be better in your scenario.
 
G

Guest

Warning: YOu should not be using a published custom form for routine email
messages to external recipients. An .oft file would be better in your
scenario.

Thank You.

Is there a way change my Form to an .oft file. I originally created the
e-mail in Outlook with all the graphics. Then I sent it to my self which
allowed me to open it then to go Tools-Forms-Publish Form. I am not and
Outlook guru and could not figure out how to save my message as a template or
even how to copy my message into a new template. (.oft files are templates,
right?)

The bottom line is this: I just want this message/form/template to be
opened instead of a blank email message when I open Outlook from MS Access
using VBA code.

Question: If I can figure out how to change my form to a template can I use
the following VBA code in my Access Module.
-----------------
Public Function SendEMail(RecipientTo As String)

Dim objOutlook As Outlook.Application
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookmsg As Outlook.MailItem
Dim MyItem As Outlook.MailItem

Set objOutlook = CreateObject("Outlook.Application")
Set MyItem = myOlApp.CreateItemFromTemplate("C:\filename.oft")

With MyItem

Set objOutlookRecip = .Recipients.Add(RecipientTo)
objOutlookRecip.Type = olTo

.Subject = "My Subject"

For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
Next

.Display

End With
Set objOutlook = Nothing
End Function
 
G

Guest

OK. I figured it out. I was able to create a template (.oft file) and I
changed my code in Access as this:
------------------------
Public Function SendEMail(RecipientTo As String)

Dim objOutlook As Outlook.Application
Dim objOutlookRecip As Outlook.Recipient
Dim MyItem As Outlook.MailItem

Set objOutlook = CreateObject("Outlook.Application")
Set MyItem = objOutlook.CreateItemFromTemplate("C:\pathtofilename.oft")

With MyItem

Set objOutlookRecip = .Recipients.Add(RecipientTo)
objOutlookRecip.Type = olTo

..Subject = "My Subject"

For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
Next

..Display

End With
Set objOutlook = Nothing
End Function
 

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