I am looking for the best way to ensure that a recordset is unique before writing it to the database??
I was considering setting up composite keys within the tables but would still rather capture it at the forms level before it reaches the tables.
I have been trying to create a function the would search through a table for a match, if it found one then would not allow the record to be written ....
This is what I had (Hardwired Prototype):
Private Function DoSQL()
Dim SQL As String
SQL = "SELECT Master_Location.Name FROM Master_Location WHERE Master_Location.Name =""Invermay"""
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset(SQL)
If rs.NoMatch Then
MsgBox "No record was found."
'Code to allow save
Else: MsgBox "A matching record has been found."
'Code to warn user that record exists
End If
rs.Close
End Function
Any help with this would be much appreciated
I was considering setting up composite keys within the tables but would still rather capture it at the forms level before it reaches the tables.
I have been trying to create a function the would search through a table for a match, if it found one then would not allow the record to be written ....
This is what I had (Hardwired Prototype):
Private Function DoSQL()
Dim SQL As String
SQL = "SELECT Master_Location.Name FROM Master_Location WHERE Master_Location.Name =""Invermay"""
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset(SQL)
If rs.NoMatch Then
MsgBox "No record was found."
'Code to allow save
Else: MsgBox "A matching record has been found."
'Code to warn user that record exists
End If
rs.Close
End Function
Any help with this would be much appreciated