mattrx731
Board Regular
- Joined
- Feb 10, 2008
- Messages
- 181
I'm using the following code in a userform, and I'd like the cursor to go back to the textbox named 'textbillingzip' if there is an error... which I thought it would do with the line
Instead it just continues to the next object in the tab order.
Code:
Me.Textbillingzip.SetFocus
Code:
'fills in zip codes
Private Sub Textbillingzip_exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim rng As Range
Set rng = Sheets("lists").Columns(25).Find(Textbillingzip.value)
If Len(Textbillingzip.value) <> 5 Then
Me.Textbillingzip.SetFocus
MsgBox "Zipcode must be 5 numbers long", vbCritical, "Zip Code"
Exit Sub
End If
If Not rng Is Nothing Then
Label42 = rng.Offset(, 1).value
Label43 = rng.Offset(, 2).value
Else
Me.Textbillingzip.SetFocus
MsgBox "Zip Code NOT found", vbExclamation, "Zip Code"
End If
End Sub