UserForm ShowModal strange behaviour

D

David OShea

I am trying to create a splash screen for Outlook which basically asks the end user if
they agree to the Email Security Policy or Not. Its a VBA UserForm that is set to show on
Application_Startup.
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Private Sub Application_Startup()
UserForm1.Show
End Sub
~~~~~~~~~~~~~~~~~~~~~~~~~~~
The ShowModal property of the form is set to True. This works fine on Outlook 2000. The
end user cannot proceed to do anything with the Outlook Application until they click the
"I Agree" button on the splach screen. If they choose not to agree then the splash screen
quits out of the application.

On Outlook 2003 the ShowModal property of the form seems to be implemented very
differently. The splash opens up no problem, but the ShowModal = True seems to only apply
to the Tool bar and Menu Bar buttons. The Close X button on the top right of the Outlook
Application is active and when clicked it closes the splash screen. Browsing the Explorer
folders and opening emails is also possible plus when the email is open Tool Bar and Menu
Bar buttons also become active on that email. All this while the "Modal ??? Form" stays on
top of the Application.

When I run the project from within VB environment it works very well. In true Modal
Fashion. The behaviour described above only happens when the application is starting up.

To me this seems like one hell of a BUG..! Or, should I say Design Feature of OL 2003 or
am I missing something?

Has anyone come accross this before. Any idea how to get around it? Any help is greatly
appricated.

Rgds
Dave O'Shea
 
D

David OShea

Looks like it's a bit of a bug in MSForms 2.0.
Instead I used Win API to get the handle of the form an set to the front, which as a
matter of fact makes it modal.

Private Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Sub UserForm_Initialize()
Dim hWnd As Long
hWnd = FindWindow("ThunderDFrame", Me.Caption)
SetForegroundWindow hWnd
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top