A
Andrew H
I'm still pretty much a novice excel programmer; I've been stumped
with the following question for a day, and I haven't seen in addressed
in the groups. Please forgive me if it has.
I've got a userform with a control called "TextBoxNoOfFilters". In a
simplified version of the problem, I need to make sure that a number
is entered, and that that number is NOT 2. If the user does enter 2,
I'd like to immediately indicate this elsewhere in the workbook (with
textboxes) and then exit the userform.
When I call the Unload Userform command, it works, but the unload
process seems to call the BeforeUpdate procedure again. Therefore, if
the user enters 2 and confirms it, the userform disappears and then
they get another msgbox asking them to confirm their entry.
I can't figure out why the unload calls the beforeupdate again, or how
to avoid that re-call.
A sketch of the code follows. Any thoughts would be most appreciated.
Thanks,
Andrew H.
Private Sub TextBoxNoOfFilters_BeforeUpdate(ByVal Cancel As
MSForms.ReturnBoolean)
If IsNumeric(TextBoxNoOfFilters) Then
If TextBoxNoOfFilters = 2 Then
msg = "Are you sure you want to enter 2?"
response = MsgBox(prompt:=msg, _
Buttons:=vbQuestion + vbYesNo, _
Title:="Confirm 2 Filters")
If response = vbYes Then
msg = "New warning message goes here"
MsgBox prompt:=msg, Buttons:=vbExclamation
'call a sub to put some text boxes on the worksheets
Unload Userform
End If
End if
Else
msg = "Please enter a number"
MsgBox prompt:=msg, Buttons:=vbExclamation
Cancel = True
TextBoxNoOfFilters = TextBoxNoOfFilters.BoundValue
End Sub
with the following question for a day, and I haven't seen in addressed
in the groups. Please forgive me if it has.
I've got a userform with a control called "TextBoxNoOfFilters". In a
simplified version of the problem, I need to make sure that a number
is entered, and that that number is NOT 2. If the user does enter 2,
I'd like to immediately indicate this elsewhere in the workbook (with
textboxes) and then exit the userform.
When I call the Unload Userform command, it works, but the unload
process seems to call the BeforeUpdate procedure again. Therefore, if
the user enters 2 and confirms it, the userform disappears and then
they get another msgbox asking them to confirm their entry.
I can't figure out why the unload calls the beforeupdate again, or how
to avoid that re-call.
A sketch of the code follows. Any thoughts would be most appreciated.
Thanks,
Andrew H.
Private Sub TextBoxNoOfFilters_BeforeUpdate(ByVal Cancel As
MSForms.ReturnBoolean)
If IsNumeric(TextBoxNoOfFilters) Then
If TextBoxNoOfFilters = 2 Then
msg = "Are you sure you want to enter 2?"
response = MsgBox(prompt:=msg, _
Buttons:=vbQuestion + vbYesNo, _
Title:="Confirm 2 Filters")
If response = vbYes Then
msg = "New warning message goes here"
MsgBox prompt:=msg, Buttons:=vbExclamation
'call a sub to put some text boxes on the worksheets
Unload Userform
End If
End if
Else
msg = "Please enter a number"
MsgBox prompt:=msg, Buttons:=vbExclamation
Cancel = True
TextBoxNoOfFilters = TextBoxNoOfFilters.BoundValue
End Sub