views:

1581

answers:

4

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.

+1  A: 

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.

Oorang
@Oorang: Thanks, I've now deleted the button, recreated it from scratch, as well as the event handler code exactly as you said, and compiled. Same problem - nothing happens when you hit the button (no reaction, breakpoint not hit, even closing the form doesn't work). Any other thoughts?
MGOwen
A: 

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.

MGOwen
Glad for you, now mark this reply as the right one.
jpinto3912
A: 

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.

A. Scagnelli
A: 

I have this same issue. I have a button that is Assigned to a Subroutine. In that subroutine, it says UserForm1.Show

But it won't respond to any clicking.

The userform works when I run the userform itself. But when I open it via the button, it doesn't respond at all. Very frustrating!