Reputation: 733
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
Upvotes: 1
Views: 7062
Reputation: 11
Thanks alot Randall! I've also found that if Outlook isn't actually opened that won't work because ActiveWindow will be null, so wrapping it up like this helps too:
If Not (oApp.ActiveWindow Is Nothing) Then 'only if there's a window
oApp.ActiveWindow.Activate 'make sure outlook comes to foreground first
End If
Upvotes: 0
Reputation: 733
I made this work by adding the following line after .SetDefaultDisplayMode olDefaultSingleName
:
OLApp.ActiveWindow.Activate
Upvotes: 2