chipsworld
Board Regular
- Joined
- May 23, 2019
- Messages
- 161
- Office Version
- 365
Hey everyone...need some guidance.
I am working on a simple userform to input data to a sheet, but am trying to eliminate duplicates...
The idea in the below code is that if the number already exists, the user gets a pop saying that the number has already been entered and then I want to set the focus back to the first text box (txtanum). Currently I can not stop it from tabbing to the second text box...how can I achieve this?
Here is the afterupdate code for the first test box on the userform. I have tried this in the "exit" field as well...always moves to the second text field....
I am working on a simple userform to input data to a sheet, but am trying to eliminate duplicates...
The idea in the below code is that if the number already exists, the user gets a pop saying that the number has already been entered and then I want to set the focus back to the first text box (txtanum). Currently I can not stop it from tabbing to the second text box...how can I achieve this?
Here is the afterupdate code for the first test box on the userform. I have tried this in the "exit" field as well...always moves to the second text field....
VBA Code:
Private Sub txtanum_AfterUpdate()
Dim ws As Worksheet
Set ws = Sheets("dBase")
If Me.txtanum.Text > "" Then
With ws
Dim Rw As Long, Fnd As Range
lkup = Me.txtanum.Value
Set Fnd = .Range("A:A").Find(lkup, LookIn:=xlValues, LookAt:=xlPart, SearchDirection:=xlPrevious)
If Not Fnd Is Nothing Then
MsgBox "That 'A' number has already been entered into the system." & vbCrLf _
& "Please use the 'Record Update' form to add or correct data.", vbOKOnly
txtanum.Text = ""
txtanum.SetFocus
End If
End With
End If
End Sub