Vba – How to bring an MS Outlook 2007 dialog to the front from MS Access 2007

ms-accessoutlookvba

I am attempting to allow a user of a MS Access 2007 database to select another user from the MS Outlook GAL. I currently have working code that opens the Outlook Select Names Dialog, but it hides behind the database window until a user clicks on Outlook.

How do I make the dialog visible to the user in VBA?

Here's my code for the dialog (typos are a result of a manual copy–this code is on an airgapped network):

set OLApp = CreateObject("Outlook.Application")
set OLDialog = OLApp.Session.GetSelectNamesDialog
with OLDialog
    .SetDefaultDisplayMode olDefaultSingleName
    if .Display then
        if OLDialog.Recipients.Count then
            theUser = OLDialog.Recipients.Item(1)
        end if
    end if
end with

Best Answer

I made this work by adding the following line after .SetDefaultDisplayMode olDefaultSingleName:

OLApp.ActiveWindow.Activate
Related Topic