Prevent leaving the control when data entered is incorrect

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!
 
S

Stuart McCall

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top