AllenRitch
Technical User
I'm sending an e-mail from Access with the following code:
Dim outLookApp As Outlook.Application
Dim eMailItem As Outlook.MailItem
Dim strTo As Outlook.Recipient
Dim strCc As Outlook.Recipient
Dim strRecipient As String, strRecipient2 As String
strSubject = "Subject"
strBody = "Message"
Set outLookApp = New Outlook.Application
Set eMailItem = outLookApp.CreateItem(olMailItem)
Set strTo = eMailItem.Recipients.Add(strRecipient)
Set strCc = eMailItem.Recipients.Add(strRecipient2)
strCc.Type = olCC
With eMailItem
.Subject = strSubject
.Body = strBody
End With
eMailItem.Display {will change to .Send once live}
The code above works fine so long as Outlook is already open. However, if I run it while Outlook is closed, I recieve error message. I've also tried a few variations of the Set statement (which also worked when Outlook was open).
So is there anyway I can have the program look to see if Outlook is open or not? If it is open I'll proceed with above. If not, I'll use the Shell function to open Outlook first.
Thanks
Dim outLookApp As Outlook.Application
Dim eMailItem As Outlook.MailItem
Dim strTo As Outlook.Recipient
Dim strCc As Outlook.Recipient
Dim strRecipient As String, strRecipient2 As String
strSubject = "Subject"
strBody = "Message"
Set outLookApp = New Outlook.Application
Set eMailItem = outLookApp.CreateItem(olMailItem)
Set strTo = eMailItem.Recipients.Add(strRecipient)
Set strCc = eMailItem.Recipients.Add(strRecipient2)
strCc.Type = olCC
With eMailItem
.Subject = strSubject
.Body = strBody
End With
eMailItem.Display {will change to .Send once live}
The code above works fine so long as Outlook is already open. However, if I run it while Outlook is closed, I recieve error message. I've also tried a few variations of the Set statement (which also worked when Outlook was open).
So is there anyway I can have the program look to see if Outlook is open or not? If it is open I'll proceed with above. If not, I'll use the Shell function to open Outlook first.
Thanks