Leventcos21
Technical User
Hi,
Upon entry of a new record I want to prevent duplicates. I relize that I can set an Keys on the table, however that would change the DB structure. Iam trying to prevent duplicates in the VBA but having some issues.
I am getting an error 91 on the Set rst. Will this work below? Thanks
Upon entry of a new record I want to prevent duplicates. I relize that I can set an Keys on the table, however that would change the DB structure. Iam trying to prevent duplicates in the VBA but having some issues.
I am getting an error 91 on the Set rst. Will this work below? Thanks
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim rst As DAO.Recordset
Dim db As DAO.Database
If Me.NewRecord Then
Set rst = db.OpenRecordset("SELECT SOP, EffectiveDate " & _
"FROM tblSop " & _
"WHERE SOP = " & Me.txtNumber & " AND EffectiveDate = me.txtEffectiveDate")
If rst.RecordCount = True Then
MsgBox " duplicates", , "dups"
rst.MoveNext
Do Until rst.EOF
rst.MoveNext
Loop
End If
rst.Close
Set rst = Nothing
End If