Flagged record check

C

cemjs

I have a table where I store all individual names entered into a database and
a seperate table of where I store flagged individual names that are added
manually when needed. Looking for assistance in getting access to search the
flagged table when a new individual is entered into the database and if a
match is found to return a message. Been trying to get this to happen using
the "after update" event procedure
 
A

Arvin Meyer [MVP]

cemjs said:
I have a table where I store all individual names entered into a database
and
a seperate table of where I store flagged individual names that are added
manually when needed. Looking for assistance in getting access to search
the
flagged table when a new individual is entered into the database and if a
match is found to return a message. Been trying to get this to happen
using
the "after update" event procedure

In the BeforeUpdate event of the textbox were the new name is added:

Private txtMyControl_BeforeUpdate(Cancel As Integer)
On Error GoTo Error_Handler
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String

strSQL = "Select * From MyTable Where NameField = '" & Me.txtMyControl & "'"

Set db = CurrentDb
Set rst = db.OpenRecordset(strSQL)

If rst.RecordCount > 0 Then
MsgBox "Duplicate Entry", vbOKOnly' "Stop"
'Cancel = True ' If you want to roll back the entry
End If

Exit_Here:
rst.Close
Set rst = Nothing
Set db = Nothing
Error_Handler:
MsgBox Err.Description
Resume Exit_Here
End Sub
 
Top