Hello All.
So I was fiddling around with the project I'm working on yesterday and came across a solution with the beforeupdate event. The only issue I am now having is my record is reset and values that were entered by the user are no longer there. Is there a way to prompt to save record and if the user clicks no then instead of cancelling new record it allows the user to continue modifying that record?
Recordsource for my main form is my CUSTOMER TABLE.
Recordsource for my subform on the main form is a query that includes two different tables; QUOTE TABLE AND QUOTEDETAILS TABLE.
QUOTE TABLE has CUSTOMERID field with a relationship connecting back to CUSTOMER TABLE.
QUOTEDETAILS has QUOTEID field with a relationship connecting back to the QUOTE TABLE.
My subform’s purpose is only for data entry of a new quote# that will include a new record (original record) that will be created also in the quotedetails table. So simentanesouly they are creating two new records (from separate tables behind the scenes) when creating a new “quote” on this form.
I created a save record prompt on the beforeupdate event. The issue I am now having is the values the user already inputted are being reset if they click no.
Here is my code in the beforeupdate event. Maybe it’s something in this code because I found it online and unclear what the heck I’m doing.
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
' This procedure checks to see if the data on the form has
' changed. If the data has changed, the procedure prompts the
' user to continue with the save operation or to cancel it. Then
' the action that triggered the BeforeUpdate event is completed.
Dim ctl As Control
On Error GoTo Err_BeforeUpdate
' The Dirty property is True if the record has been changed.
If Me.Dirty Then
' Prompt to confirm the save operation.
If MsgBox("Note:" & vbCrLf & "If all REQUIRED (*) FIELDS are not filled out new records will not be saved after the YES button is selected below. If an error message displays under the QUOTEID field after record has been saved push ESC and start over." & vbCrLf & vbCrLf & ">> Please click YES to SAVE NEW RECORD." & vbCrLf & vbCrLf & ">> Please click NO to cancel and REVIEW your record BEFORE saving.", vbYesNo + vbQuestion, _
"Save Record") = vbNo Then
Me.Undo
End If
End If
Exit_BeforeUpdate:
Exit Sub
Err_BeforeUpdate:
MsgBox Err.Number & " " & Err.Description
Resume Exit_BeforeUpdate
End Sub