Code hangs after opening Outlook.

jonno_g

Registered User.
Local time
Today, 14:12
Joined
May 30, 2007
Messages
52
I have some simple code that checks for the presence of Outlook, and if it's not already running then it launches it. Problem is that it then won't return to Access and continue execution of the code unless I manually return focus to either the VBA editor or Access itself, then it continues on as if nothing went wrong and compiles the email as per normal.

Here is the code I'm using currently, if anyone has a better way to achieve the same end please let me know. I don't want to roll out my project like this, as users may see this and think that the DB has crashed on them. (And I'll get inundated with phonecalls! :( )

Code:
    On Error Resume Next
    Set objOutlook = GetObject(, "Outlook.Application")
 
    If Err.Number = 429 Then
 
        Shell "C:\Program Files (x86)\Microsoft Office\Office12\Outlook.exe", vbNormalNoFocus
        [COLOR=darkgreen]'This is where it stops processing and sits waiting for user intervention.[/COLOR]
        Err.Clear
 
        While objOutlook.Name <> "Outlook"
            Set objOutlook = GetObject(, "Outlook.Application")
        Wend
 
        Err.Clear
 
        objOutlook.ActiveWindow.WindowState = olMinimized
 
    ElseIf Err.Number <> 0 Then
 
        GoTo Err_RequestChangeEmail_Click
 
    End If
 
    On Error GoTo Err_RequestChangeEmail_Click

Any help greatly appreciated. I've tried everything I can think of today, but I've not made any progress.

Cheers,...Jon.
 
Try replacing GetObject by CreateObject. (CreateObject gets the object if it already exists, if the app is set to permit only one instance, like Outlook) then you don't need to check for it

(a Shell is a fire-and-forget tool, that does what you told it too, and is not in anyway synchronous with access code, so not so good for your bypass operation anyway :-) - there is a version lurking on the net called shellandwait - google for it. But don't use it here either)
 
Thankyou!

Of course it's obvious now that you've pointed it out.

What you've suggested has actually allowed me to completely do away with the snippet of code that I posted in my first post, as all I really needed to do was to swap 'GetObject' for 'CreateObject' in my mailer module - a one word change saves 13 lines of code! :D
 

Users who are viewing this thread

Back
Top Bottom