G
Guest
I have 3 buttons on my form Add Record, Save Changes, and Cancel/Refresh.
They work fine.
However, I put a confirmation msgbox in the BeforeUpdate event, because
users are able to use the record selectors to move to another record forcing
the beforeupdate/afterupdate events. From the msgbox the user can save
changes, cancel changes or return to the record they were editing. That
works fine too.
My issue is the user experience of having to press two buttons to save
changes first on the form and then the msgbox that fires in BeforeUpdate.
I'd like to have some sort of conditional check in the BeforeUpdate event to
skip the msgbox if the SaveChanges button was clicked. I just don't know the
best way to pass a parameter from the button click event to the beforeupdate
event.
Any help would be appreciated. Here is my code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim Msg, Style, Title,Response
Msg = "Save Changes?"
Style = vbYesNoCancel + vbCritical + vbDefaultButton2
Title = "You are leaving this record"
'Display message.
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbYes Then
'Do Nothing - Go Straight to AfterUpdate
Else
If Response = vbNo Then Me.Undo Else Cancel = True
End If
End Sub
Private Sub SavePVRecord_Click()
On Error GoTo Err_SavePVRecord_Click
Me.SavePVRecord
Exit_SavePVRecord_Click:
Exit Sub
Err_SavePVRecord_Click:
MsgBox Err.Description
Resume Exit_SavePVRecord_Click
End Sub
They work fine.
However, I put a confirmation msgbox in the BeforeUpdate event, because
users are able to use the record selectors to move to another record forcing
the beforeupdate/afterupdate events. From the msgbox the user can save
changes, cancel changes or return to the record they were editing. That
works fine too.
My issue is the user experience of having to press two buttons to save
changes first on the form and then the msgbox that fires in BeforeUpdate.
I'd like to have some sort of conditional check in the BeforeUpdate event to
skip the msgbox if the SaveChanges button was clicked. I just don't know the
best way to pass a parameter from the button click event to the beforeupdate
event.
Any help would be appreciated. Here is my code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim Msg, Style, Title,Response
Msg = "Save Changes?"
Style = vbYesNoCancel + vbCritical + vbDefaultButton2
Title = "You are leaving this record"
'Display message.
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbYes Then
'Do Nothing - Go Straight to AfterUpdate
Else
If Response = vbNo Then Me.Undo Else Cancel = True
End If
End Sub
Private Sub SavePVRecord_Click()
On Error GoTo Err_SavePVRecord_Click
Me.SavePVRecord
Exit_SavePVRecord_Click:
Exit Sub
Err_SavePVRecord_Click:
MsgBox Err.Description
Resume Exit_SavePVRecord_Click
End Sub