M
moshe via AccessMonster.com
I have a form and when the user enters new information I want to send them an
email.
I tried several ways to create the email and finely got the best of them, but
if outlook is closed I get an error. so I added code the shell function
should open outlook but I don't want outlook to get the focus? "shell
"outlook.exe",vbhide" don't seems to working it always opens in normal window.
also if outlook is already open I don't want it to be opened twice, or it
should close after it sends the email. so by that way outlook will not stay
open twice, I tried to close it down by using sendkeys but it closed my
database instead of outlook, or if someone could tell me how to send the
email without outlook open would be great, my code is as follow all comments
greatly appreciated.
Public Sub SendMessage(DisplayMsg As Boolean)
 Dim  objOutlook As Outlook.Application
 Dim objOutlookMsg As  Outlook.MailItem
Â
 ' Create the Outlook session.
 Set  objOutlook =CreateObject("Outlook.Application")
 shell  "outlook.exe", vbHide 'this line I added to the samples
 ' Create the  message.
 Set objOutlookMsg =  objOutlook.CreateItem(olMailItem)
 With  objOutlookMsg
 .To = "moshe"
 .Subject = "This is an Automation test with Microsoft  Outlook"
 .body = "This is the body of  the message." & vbCrLf & vbCrLf
 .Importance = olImportanceHigh 'High  importance
 .Send 'here is where I get the error
 End With
 Set objOutlook = Nothing
Â
 End Sub
email.
I tried several ways to create the email and finely got the best of them, but
if outlook is closed I get an error. so I added code the shell function
should open outlook but I don't want outlook to get the focus? "shell
"outlook.exe",vbhide" don't seems to working it always opens in normal window.
also if outlook is already open I don't want it to be opened twice, or it
should close after it sends the email. so by that way outlook will not stay
open twice, I tried to close it down by using sendkeys but it closed my
database instead of outlook, or if someone could tell me how to send the
email without outlook open would be great, my code is as follow all comments
greatly appreciated.
Public Sub SendMessage(DisplayMsg As Boolean)
 Dim  objOutlook As Outlook.Application
 Dim objOutlookMsg As  Outlook.MailItem
Â
 ' Create the Outlook session.
 Set  objOutlook =CreateObject("Outlook.Application")
 shell  "outlook.exe", vbHide 'this line I added to the samples
 ' Create the  message.
 Set objOutlookMsg =  objOutlook.CreateItem(olMailItem)
 With  objOutlookMsg
 .To = "moshe"
 .Subject = "This is an Automation test with Microsoft  Outlook"
 .body = "This is the body of  the message." & vbCrLf & vbCrLf
 .Importance = olImportanceHigh 'High  importance
 .Send 'here is where I get the error
 End With
 Set objOutlook = Nothing
Â
 End Sub