Hi,
When users add new record and the record already exist in the table, how do I cancel the AddNewRecord action and make the form navigate to the existed record ? Thanks.
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
strSQL = "SELECT * FROM myTable WHERE ID = " & Chr(34) & Me![txtID] & Chr(34) & _
" AND Year = " & Chr(34) & Me![txtYear] & Chr(34)
Set db = CurrentDb
Set rs = db.OpenRecordset(strSQL)
With rs
If .BOF And .EOF Then
Me.AllowEdits = True
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
MsgBox "Record has been saved
Else
MsgBox "Record already exists in the table."
??????????????????????????????????
Exit Sub
End if
When users add new record and the record already exist in the table, how do I cancel the AddNewRecord action and make the form navigate to the existed record ? Thanks.
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
strSQL = "SELECT * FROM myTable WHERE ID = " & Chr(34) & Me![txtID] & Chr(34) & _
" AND Year = " & Chr(34) & Me![txtYear] & Chr(34)
Set db = CurrentDb
Set rs = db.OpenRecordset(strSQL)
With rs
If .BOF And .EOF Then
Me.AllowEdits = True
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
MsgBox "Record has been saved
Else
MsgBox "Record already exists in the table."
??????????????????????????????????
Exit Sub
End if