How do I bring an MS Outlook 2007 dialog to the front from MS Access 2007?
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 net开发者_开发问答work):
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
I made this work by adding the following line after .SetDefaultDisplayMode olDefaultSingleName
:
OLApp.ActiveWindow.Activate
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
精彩评论