Code or a link

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, anybody could help me to find a way where in once I enter a new badge
number to a textbox it will tell me whethere that Number is already existing
or not if it is exist it will display that record on the form.

Hope to get an answer.

Thanks..

Truly yours,
Kenji
 
Hi, anybody could help me to find a way where in once I enter a new badge
number to a textbox it will tell me whethere that Number is already existing
or not if it is exist it will display that record on the form.

Try putting code like this in the BeforeUpdate event of the textbox:

Private Sub txtBadgeNumber_BeforeUpdate(Cancel as Integer)
Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone 'assumes that the form is not
'filtered
rs.FindFirst "[BadgeNumber] = '" & Me!txtBadgeNumber & "'"
' leave off the ' and "'" if the field is numeric
If Not rs.NoMatch Then ' a record was found
Me.Undo ' erase what the user has entered
Cancel = True ' stop the update
Me.Bookmark = rs.Bookmark ' move to the found record
End If
Set rs = Nothing
End Sub

John W. Vinson[MVP]
 
Back
Top