Opening MS Outlook before running a query....

Moonshine

Registered User.
Local time
Today, 18:05
Joined
Jan 29, 2003
Messages
125
Hi all

The onload event of a form, runs two query's and then emails a couple of people the results..

This works fine as long as the person opening the database (has multiple users) has Outlook open, they have been told to have it open before opening the database, but sometimes they forget and they get the prompt to select a profile.... Which confuses them.

Is there anyway that the onload event of the form, can open outlook, and then close it again when the queries have been run?

Scott
 
Grasping at straws but I seem to recall a "Call Shell()" command, with the file path in the () that will open programs.

you'll probably need to check to see if outlook is open first though

hope this gets you started at least
 
Thanks for that, will look into it :)
 
HI again, thought id resurect an old thread :)

This project got put on the backburner for a bit, and am now only just getting back to it..

Well this suggestion i couldnt find any help on, so im still stuck with the problem :/ It sounds easy what i want to do, but is proving one of the hardest things to find out how to do, for me anyway!

All of the machines that are using it, will have outlook installed in the exact same file location, so that helps one problem :) What i want it to bascially do is:

1. Check For Outlook to see if its open in the forms "onLoad" event.

2. If it is, just open the form and carry on as normal.

3. If it isnt, open outlook, minimise it, and set the focus back the the Access applcation

4. Carry on opening the form.


it seems easy, please can any one help!!??

Ta, Scott
 
Hi Scott,

I have several program's that do a similar thing. I have attached a really simple example that includes the open and close events plus a command button event which sends a mail.

I have not documented the code, if you require any explanation, just reply to this topic.

One final thing, i have not tested this with sendobject, it uses CreateItem(olMailItem) from outlook!!

Bretto
 

Attachments

Hi Bretto, and thanks for the text. It looks very promising apart from one thing...

It seems only to set the MyAuto on error... is that correct?

I was trying to test it, so that i could just click a button and it would give me a true or false if outlook was running or not. From that i can build on it.
 
Last edited:
You need to add a reference to the outlook library so with the db in question open, go into VBA then open Tools/References and tick the check box for (in mycase Outlook 2000) "Microsoft Outlook 9.0 Object Library", or whichever outlook you are using.
 
Hi bretto, i found that one thanks :) I changed the code a little, bascially your Onload is now a button click, as is the formclose. Here is what i came up with.


Private Sub Command0_Click()
On Error GoTo error_sect

'test for existing outlook instance, if not found start a new one
Set myoutlook = GetObject(, Outlook.Application)

If myoutlook = False Then
Set myoutlook = CreateObject(Outlook.Application)
myauto = True
MsgBox "Outlook Opened"
Else
If myoutlook = True Then
MsgBox "Outlook Already Open"
End If
End If

Exit Sub

error_sect:

If Err.Number = 429 Then
myauto = True
Resume Next
Else
'warn the user a non automation error has occured
MsgBox Err.Description, vbCritical, "Error, program will now stop"
End
End If
End Sub

Private Sub Command1_Click()
If myauto = True Then
myoutlook.Quit
MsgBox "Outlook Closed"
End If
Set myoutlook = Nothing
End Sub



Now, it works of a fashion. If outlook isnt running, it opens it fine. If i then try and close it it will not close it. And if i click on the OPen outlook again, it gives me the message box "Outlook Opened" when it shouldnt, because it's already open!

From what i can read of your original text, it doesnt set the MyAuto til an error, is that correct? Also, i tried yours in my point, with 2 buttons. And it opens Outlook but then closes it as soon as it opens :/

Im getting puzzled now!
 
SO, in my simple terms.

1. Click Button "Open Outlook", if outlook is already running pop up a message box "Outlook Already Open" if its not already open pop up a message box "Outlook Open" and then open outlook.

2. Click Button "Close Outlook", it its open close it, and pop up a message box telling me, if its not dont do anything!

Seems simple, but not for me :) hehe
 

Users who are viewing this thread

Back
Top Bottom