Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to SetFocus if no matching record found - not working

Status
Not open for further replies.

RobertIngles

Technical User
Jan 20, 2011
113
CA
If the user enters an invalid UserID then the error msg pops and the field resets - Works perfectly.

If the UserID is not matched then the inputer may continue creating a new record and I want the cursor to move to the next field.

What is wrong with my SetFocus statement?

Private Sub LaptopUserID_BeforeUpdate(Cancel As Integer)
'Create var.
Dim intChk As Integer

'This line counts the number of rec instances in TBLUser.
intChk = DCount("*", "TBLUser", "[UserID] = '" & Forms!FRMCreateNewLaptopandUserV3!LaptopUserID & "'")

'Does the rec exist? If not then Move to field Barcode and continue entry.
If intChk = 0 Then
Me.Barcode.SetFocus

Else

MsgBox "This UserID Already Exists", vbCritical
Cancel = True
Me.Undo

End If
End Sub

Thanks
Robert


 
Figured it out - Changed the statement to:

Private Sub LaptopUserID_BeforeUpdate(Cancel As Integer)
'Create var.
Dim intChk As Integer

'This line counts the number of rec instances in TBLUser.
intChk = DCount("*", "TBLUser", "[UserID] = '" & Forms!FRMCreateNewLaptopandUserV3!LaptopUserID & "'")


'Does the rec exist? If not then Move to field Barcode.
If intChk > 0 Then
MsgBox "This UserID Already Exists", vbCritical
Cancel = True
Me.Undo

And left out any SetFocus reference as it is not needed if IntChk>0
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top