Solved Query in form not populating field (1 Viewer)

Sh8dyDan

New member
Local time
Today, 07:06
Joined
Dec 15, 2022
Messages
26
You can't have this code inside the form's BeforeUpdate event.
Code:
If Me.Dirty Then
    Beep
    Response = MsgBox(Msg, Style, Title, Help, Ctxt)
    If Response = vbYes Then
        DoCmd.Save
    End If
    If Response = vbNo Then
        Me.Undo
        T1_RequeryControls
    End If
Else
    DoCmd.Close
End If

DoCmd.Save doesn't save a record. It saves the form which should never have been changed by the user so it irrelevant. If you were to insert an actual save record command such as DoCmd.RunCommand acCmdSaveRecord, you would get an error since you are already in the save process once this event runs so you cannot restart the save from within the BeforeUpdate event.

The code should be more like this. There is no need to check for dirty. This event only runs if the form is dirty so the If is redundant.
Code:
    Response = MsgBox(Msg, Style, Title, Help, Ctxt)
    If Response = vbYes Then
    Else
        Me.Undo
        Cancel = True
    End If
Yes, I definitely used the wrong save there. Thank you for pointing it out. I'm trying and learning as I go along. The last time I used Access was in the early 2000s. I only picked it back up a month ago.
 

Users who are viewing this thread

Top Bottom