flag a file that exist?

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

Guest

I have a form that I enter serial numbers in. I was wondering if there is a
way to tell if a number has already been entered. I would like something
that would tell me the number already exist or something like that, and have
the option to view that record. Can this be done? If so how would I do this.
I'm still learning access. There is so much more to learn. Thanks in
advance.
Jane
 
Use the Before Update event of the control where you enter the serial number.
The code below will ask the user if they want to cancel the entry or view
the existing record. Since I don't know the names you are using, these are
made up for example purposes.

Private Sub txtSerNo_BeForeUpdate(Cancel As Integer)

If Not IsNull(DLookup("[SerialNumber]","TableNameHere", "[SerialNumber]
= '" & Me.txtSerNo) Then 'The serial number is already in the table
Cancel = True 'Cancels updating the field
If MsgBox(Me.txtSerNo & " Is in the Table" & vbNewLine & "OK to View
the Record", vbQuestion + vbOkCancel) = vbOk Then
With Me.RecordsetClone
.FindFirst "[SerialNumber] = '" & Me.txtSerNo & "'"
If Not .NoMatch Then
Me.Bookmark = .Bookmark
End If
End With
Else
Me.txtSerNo.Undo
End If
End If
End Sub
 
Back
Top