I am wanting to do a find command on the database on a before update event. I have the part that it will find the record if it already exist or not.
Next I want to have a vbYesNo Message box to ask the user if they want to continue and create a duplicate record, if so it will continue if "yes" is clicked. If "no" is clicked it will move to the first record of the database and in effect cancel before it updates and saves the record to the database. I am getting an error stating it cannot move to the first record. below is my code:
Private Sub UserID_BeforeUpdate(Cancel As Integer)
MsgBox "searching before updating"
Dim Criteria As String
Dim IDName As String
Dim MyRS As DAO.Recordset ' Recordset used to search.
Set MyRS = Me.RecordsetClone
IDName = Chr$(34) & UserID.Text & Chr$(34)
Criteria = "[IDNAME]=" & IDName
MyRS.FindFirst Criteria
If MyRS.NoMatch Then
MsgBox "User ID: " & UserID.Text & " not in database, Click OK to continue to save."
Else
Dim msgstring As String
Dim message
msgstring = "ID already exist in database, do you want to continue to save ID in database and make a duplicate record?"
message = MsgBox(msgstring, vbYesNo)
If message = vbNo Then
DoCmd.GoToRecord acDataForm, "frmNSAP", acGoTo, 1
End If
End If
MyRS.Close
End Sub
Next I want to have a vbYesNo Message box to ask the user if they want to continue and create a duplicate record, if so it will continue if "yes" is clicked. If "no" is clicked it will move to the first record of the database and in effect cancel before it updates and saves the record to the database. I am getting an error stating it cannot move to the first record. below is my code:
Private Sub UserID_BeforeUpdate(Cancel As Integer)
MsgBox "searching before updating"
Dim Criteria As String
Dim IDName As String
Dim MyRS As DAO.Recordset ' Recordset used to search.
Set MyRS = Me.RecordsetClone
IDName = Chr$(34) & UserID.Text & Chr$(34)
Criteria = "[IDNAME]=" & IDName
MyRS.FindFirst Criteria
If MyRS.NoMatch Then
MsgBox "User ID: " & UserID.Text & " not in database, Click OK to continue to save."
Else
Dim msgstring As String
Dim message
msgstring = "ID already exist in database, do you want to continue to save ID in database and make a duplicate record?"
message = MsgBox(msgstring, vbYesNo)
If message = vbNo Then
DoCmd.GoToRecord acDataForm, "frmNSAP", acGoTo, 1
End If
End If
MyRS.Close
End Sub