Userform_Terminate

G

Gojavid

I have a form that I'm trying to add some code to that will require a
combobox to be filled in before it is closed.

The problem:

The code I've put under the userform_terminate shows the form, but it
won't close when combobox event has been completed. It doesn't seem
to be calling the combobox_change event after the terminate button has
been pushed.


The code:

Private Sub UserForm_Terminate()
MsgBox ("Please select an instrument. This step is required to
continue.")
fmr_instrumentselect.show
End Sub


Any ideas?
 
B

Bob Phillips

You can't use Terminate, the form is shutting down at this point. Add an OK
button and check it in there.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
D

Dave Peterson

Maybe you could change the Cancel's button .takefocusonclick property to false.
 
G

Gojavid

You can't use Terminate, the form is shutting down at this point. Add an OK
button and check it in there.


Thanks for the advice. I have the form open as part of the
workbook_open so I just added the code to that.
 
D

Dave Peterson

I put a textbox and two commandbuttons on a small userform. This was the code
behind it:

Option Explicit
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
MsgBox "trying to exit"
'and never let them (just for testing)
Cancel = True
End Sub
Private Sub UserForm_Initialize()
With Me.CommandButton1
.Caption = "Cancel"
.TakeFocusOnClick = False
End With

With Me.CommandButton2
.Caption = "Ok"
End With
End Sub
 
D

Dave Peterson

Ps.

I figured your code would have at least two buttons on it.

One that has a caption of "ok" (or something like that).

And one that has a caption of "Cancel") (or equivalent).
 
G

Gojavid

It works great. Thanks for the advice!



Ps.

I figured your code would have at least two buttons on it.

One that has a caption of "ok" (or something like that).

And one that has a caption of "Cancel") (or equivalent).
 
Top