albertc30
Well-known Member
- Joined
- May 7, 2012
- Messages
- 1,091
- Office Version
- 2019
- Platform
- Windows
Hello everyone.
I am back again.
The code bellow is working to an extent. However, when I click OK to the Error I get, it clears the field BUT the customer name field (tbnbna) does not get the setfocus.
Now, on another note, is it good practice to have this code checking for the duplicated entries on the field itself, or is it better practice to have it when the form is executed via the command botton?
The reason I am currently doing it this way to not waste the user's time filling the entire form only then to get an error. On the other hand, I suppose even upon error with duplicated customer name, I guess it would be just the case to setfocus to that field and entering a different name and then submitting the form which would be otherwise already filled in.
Any help, as always, much appreciated.
Cheers.
I am back again.
The code bellow is working to an extent. However, when I click OK to the Error I get, it clears the field BUT the customer name field (tbnbna) does not get the setfocus.
Code:
Private Sub tbnbna_AfterUpdate() If Application.WorksheetFunction.CountIf(Range("A:A"), Me.tbnbna) > 0 Then
MsgBox "Customer already exists!"
Me.tbnbna.Value = "" 'This line works...
[COLOR=#ff0000] Me.tbnbna.SetFocus 'But this line of code is not working as the cursor is moving along to the next textbox![/COLOR]
adcubton.Enabled = False 'This line also works...
Exit Sub
End If
adcubton.Enabled = True
End Sub
Private Sub tbnbna_Change()
tbnbna.Text = UCase(tbnbna.Text)
End Sub
Now, on another note, is it good practice to have this code checking for the duplicated entries on the field itself, or is it better practice to have it when the form is executed via the command botton?
The reason I am currently doing it this way to not waste the user's time filling the entire form only then to get an error. On the other hand, I suppose even upon error with duplicated customer name, I guess it would be just the case to setfocus to that field and entering a different name and then submitting the form which would be otherwise already filled in.
Any help, as always, much appreciated.
Cheers.