Question

I've created a simple UserForm in my Outlook VBA macro - I can make the form visible using this code:

VBA.UserForms.Add (PasswordForm.Name)
PasswordForm.Show (Modal)

...and the UserForm_Initialize() Event does in fact fire. But clicking on the "Submit" button on the form does nothing - the SubmitButton_Click() Event (which was auto-created by double clicking on the button in the designer) never fires. Also, the userform has the usual little red X in the top right corner of the window, but clicking this doesn't do anything (the form doesn't close or exit).

Any idea what I might be doing wrong? I'm quite new to VBA.

Was it helpful?

Solution 2

OK, solved: I changed:

PasswordForm.Show (Modal)

to

PasswordForm.Show

and it now works, although I'll have to change the way it works a bit to accommodate the fact that the form won't be modal any more (I suppose it's the better solution anyway, modals can be annoying to the user, it's just I have to check that they submitted the form, etc now).

Thanks all for your suggestions.

OTHER TIPS

Sometimes controls in VBA get decoupled from their events. It can be because you renamed the control or because you accidentally renamed the event procedure (although it rarely can happen for other reasons). Also, ff you have forgotten to "compile" before running the form, you may have an error on the form that is causing the issue.

The easiest way to double check is to open the form in design view, select the button in question and press F7. If a new procedure is created, copy an paste your code then just copy/paste your old code into it, and get rid of the old one.

After you have done that, go to the "Debug" menu and click "compile". If any errors are detected, correct them an click "Compile" again. Repeat until it compiles without complaint. Then try running your form again.

In Office 03/07, if you want to make sure it shows modal, set the form's .ShowModal behavior to "True". I've had issues with trying to make the form modal during the show event.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top