Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I tell when an application is already open or loaded?

Status
Not open for further replies.

AllenRitch

Technical User
May 20, 2003
52
US
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

The problem with the code above is that it won't work unless Outlook is already opened. Is there anyway I can have the program look to see if Outlook is open or not? I plan on using the Shell function to open Outlook if it's closed.

Thanks
 
I use the same type of code. Change the ordering as shown below and it should work.


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


Set outLookApp = New Outlook.Application
Set eMailItem = outLookApp.CreateItem(olMailItem)
strSubject = "Subject"
strBody = "Message"
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

This second part is the code I use:


'Set myOlApp = CreateObject("Outlook.application")
'Set myItem = myOlApp.CreateItem(olMailItem)
'Set myRecipients = myItem.Recipients
'Set myAttachments = myItem.Attachments

'myRecipients.Add ("John")
'myItem.Subject = "Parts on Hold"
'myItem.Body = "The attached parts are on hold."
'myAttachments.Add "c:\Alerts\Quality Alert.pdf"
'myItem.Send

John Green
 
I should've added that you shouldn't have to have Outlook running to use this code, but make sure you have the references loaded for Outlook in the Access module.

John Green
 
I've tested what I have and works fine so long as Outlook is open. However, when Outlook is closed and I try running it, I recieve a message stating, "Internal Application Error". I'm also presently using .display instead of .send since the database isn't in production yet.

What do you mean by making sure I have the refrences loaded for Outlook in an Access Module? The code I have above is embedded in a button's on-click event. Is there more I need to do?

Thanks
 
When you're in the VB editor go to the Tools menu and click on references. Make sure there is a check next to the Outlook Object Library. You also might want to try using the CreateObject code I used, that should allow you to send the e-mail without first opening Outlook (it opens it).

John Green
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top