N
Neal
Dear All,
I have a userform with a couple of textboxes and an OK and Cancel button at
the bottom of the form. After consulting this news group, I found the Exit
event (I was using the AfterUpdate event before, but wanted the setfocus to
be in a certain textbox.) For validation purposes, I have set up the Exit
event as you can see in the following:
Private Sub SymbolBox_Exit(ByVal cancel As MSForms.ReturnBoolean)
'
Dim RngFound As Range, SymbolRange As Range 'SellRange as Range
Dim SellSymbol As String ' LstRow As Integer
If SymbolBox.Value = "ABC" Then
If Not IsNumeric(SymbolBox.Value) Then
SymbolBox.Value = UCase(SymbolBox.Value)
SellBox.SetFocus
Else
MsgBox "Need to type in a valid symbol"
cancel = True
SymbolBox.Text = ""
SymbolBox.SetFocus
End If
Else
MsgBox "Need to enter a symbol"
cancel = True
SymbolBox.Text = ""
SymbolBox.SetFocus
'Exit Sub
End If
End Sub
The problem is if the user does not enter any data, but wants to exit the
form and clicks on the Cancel button, nothing happens. The userform does not
close. How can I get the userform to close? Thanks in advance.
Neal
I have a userform with a couple of textboxes and an OK and Cancel button at
the bottom of the form. After consulting this news group, I found the Exit
event (I was using the AfterUpdate event before, but wanted the setfocus to
be in a certain textbox.) For validation purposes, I have set up the Exit
event as you can see in the following:
Private Sub SymbolBox_Exit(ByVal cancel As MSForms.ReturnBoolean)
'
Dim RngFound As Range, SymbolRange As Range 'SellRange as Range
Dim SellSymbol As String ' LstRow As Integer
If SymbolBox.Value = "ABC" Then
If Not IsNumeric(SymbolBox.Value) Then
SymbolBox.Value = UCase(SymbolBox.Value)
SellBox.SetFocus
Else
MsgBox "Need to type in a valid symbol"
cancel = True
SymbolBox.Text = ""
SymbolBox.SetFocus
End If
Else
MsgBox "Need to enter a symbol"
cancel = True
SymbolBox.Text = ""
SymbolBox.SetFocus
'Exit Sub
End If
End Sub
The problem is if the user does not enter any data, but wants to exit the
form and clicks on the Cancel button, nothing happens. The userform does not
close. How can I get the userform to close? Thanks in advance.
Neal