I'm trying to do a vba insert - where the newest "LOAN_ID" of a table called "LOANS" Is inserted into a table called "PAYMENTS" along with the current date being inserted into a "DATE_OF_PAYMENT" field also in the PAYMENTS table. Here's what I have:
'------------------------------------------------------------
' NEW_LOAN
'
'------------------------------------------------------------
Function NEW_LOAN()
On Error GoTo NEW_LOAN_Err
With CodeContextObject
If (.ORIGINAL_AMOUNT > 0) Then
DoCmd.RunCommand acCmdSaveRecord
DoCmd.RefreshRecord
Beep
MsgBox "Saved Loan", vbInformation, "LOAN SAVED"
DoCmd.RunCommand acCmdRefresh
Else
DoCmd.RefreshRecord
Beep
MsgBox "Loan amount is missing.", vbExclamation, "ENTER AMOUNT:"
End If
DoCmd.Close acForm, "New Loan"
Dim lastID As Integer
strSQL = "INSERT INTO PAYMENTS (LOAN_ID, DATE_OF_PAYMENT) VALUES (lastID, DATE())"
DoCmd.RunSQL (strSQL)
lastID = DMax("[LOAN_ID]", "LOANS")
End With
NEW_LOAN_Exit:
Exit Function
NEW_LOAN_Err:
MsgBox Error$
Resume NEW_LOAN_Exit
End Function