Hello,
I know just enough about VBA and queries to get done what I need to, I'm no expert so any help with the below is appreciated.
I need to enter a record into the table, check for a duplicate record before update and if one is located; I need an update query to run on the new record I am entering via the form.
The code checks for the duplicate and displays the warning message fine, my disconnect is with the update query. I can't seem to get it to select the current record set.
VBA and query code as follows:
VBA
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String
strMsg = strMsg & "Do you want to add loan to master list?"
If MsgBox(strMsg, vbQuestion + vbYesNo, "Add New Loan") = vbYes Then
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("MasterList", dbOpenSnapshot)
rs.FindFirst "LoanNumber = """ & Me![LoanNumber] & """"
If Not rs.NoMatch Then
DoCmd.SetWarnings False
If MsgBox("This loan already exists in the database. Do you want to continue?", vbYesNo, "Duplicate Loan Warning") = vbYes Then
DoCmd.OpenQuery "Reinstate Query"
End If
DoCmd.SetWarnings True
Else
DoCmd.RunCommand acCmdUndo
'For Access 95, use DoMenuItem instead
'DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
End If
End If
End Sub
QUERY
UPDATE MasterList SET MasterList.ReinstatedLoanAlert = "[text]", MasterList.LoanReinstated = True
WHERE (((MasterList.LoanNumber)=[Forms]![Add New Loans]![Loan Number]));