Prevent leaving the control when data entered is incorrect

  • Thread starter Thread starter Angel G
  • Start date Start date
A

Angel G

What is the best approach for preventing moving to a different control?
CurrentPIN is the control that I do not want to leave if the data entered is
incorrect.
I have used CurrentPIN.SetFocus and docmd.gotocontol "CurrentPIN". And the
cursor goes to the password control when the incorrect PIN has been used.
What am I missing?
Here is my code:

Private Sub CurrentPIN_AfterUpdate()
If CurrentPIN <> UserPIN Then
MsgBox "Incorrect Pin number used. Please Try again", vbCritical, "Invalid
PIN number"
NewPIN1.Enabled = False
NewPin.Enabled = False
CurrentPIN = ""
CurrentPIN.SetFocus
Else
NewPIN1.Enabled = True
NewPin.Enabled = True
End If
End Sub

Any input is appreciated
Thanks!
 
Angel G said:
What is the best approach for preventing moving to a different control?
CurrentPIN is the control that I do not want to leave if the data entered
is incorrect.
I have used CurrentPIN.SetFocus and docmd.gotocontol "CurrentPIN". And the
cursor goes to the password control when the incorrect PIN has been used.
What am I missing?
Here is my code:

Private Sub CurrentPIN_AfterUpdate()
If CurrentPIN <> UserPIN Then
MsgBox "Incorrect Pin number used. Please Try again", vbCritical, "Invalid
PIN number"
NewPIN1.Enabled = False
NewPin.Enabled = False
CurrentPIN = ""
CurrentPIN.SetFocus
Else
NewPIN1.Enabled = True
NewPin.Enabled = True
End If
End Sub

Any input is appreciated
Thanks!

Move your code to CurrentPIN's BeforeUpdate event, and replace:

CurrentPIN.SetFocus

with:

Cancel = True

See help for the BeforeUpdate event for an explanation.
 
Back
Top