Help with opening Outlook VBA via access (2 Viewers)

gojets1721

Registered User.
Local time
Today, 04:47
Joined
Jun 11, 2019
Messages
430
Bit of an odd one...I use the below code to pull up Outlook and search something in the search bar. It works well except for one odd quirk.

Code:
Sub FilterOutlook(searchString As String)

Const olMaximized = 0
Dim app As Outlook.Application

On Error Resume Next

Set app = GetObject(, "Outlook.Application")

If app Is Nothing Then
    MsgBox "Please open Outlook."
Else
    app.ActiveExplorer.WindowState = olMaximized
    
    app.ActiveExplorer.Search searchString, olSearchScopeAllFolders
    
    Set app = Nothing
    
End If
End Sub

Ideally, when the code is executed by the user, then Outlook will pull up immediately on the user's screen (please note: Outlook must already be open for this code to work or else the user gets a message box)

If the Outlook is minimized, then it works perfectly. The user executes the code and then Outlook pulls up.

However, if Outlook is maximized, but simply has another screen in front of it (like Chrome for instance), then Outlook doesn't open in front of Chrome. It'll still search fine, but the user needs to click on the Outlook icon to get to it or minimize whatever is in front (like the Chrome)

Curious if there's a way around that (maybe not). It's not a huge issue but it would be nice if Outlook always pulled up, whether it was minimized or not.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 04:47
Joined
Oct 29, 2018
Messages
21,473
May have to go with API calls...
 

gojets1721

Registered User.
Local time
Today, 04:47
Joined
Jun 11, 2019
Messages
430
Like to minimize chrome, other apps?
 

Users who are viewing this thread

Top Bottom