When I use the following code it does not run the before update
Form_KeyPress
but when I have it run through this code
CloseForm_Click
it works fine if you are wondering this is what is in my before_update
Before_Update
and then it goes to onunload
Form_Unload
Save_Check
Form_KeyPress
PHP:
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyEscape Then
DoCmd.Close
End If
End Sub
but when I have it run through this code
CloseForm_Click
PHP:
Private Sub CloseForm_Click() 'Button
On Error GoTo Err_CloseForm_Click
DoCmd.Close
Exit_CloseForm_Click:
Exit Sub
Err_CloseForm_Click:
MsgBox Err.Description
Resume Exit_CloseForm_Click
End Sub
it works fine if you are wondering this is what is in my before_update
Before_Update
PHP:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Checkme = True
End Sub
and then it goes to onunload
Form_Unload
PHP:
Sub Form_Unload(Cancel As Integer)
On Error GoTo Form_Unload_Err
Call Save_Check
Form_Unload_Exit:
Exit Sub
Form_Unload_Err:
MsgBox Error$
Resume Form_Unload_Exit
End Sub
Save_Check
PHP:
Private Sub Save_Check()
If Checkme = True Then
Dim strMsg As String
strMsg = "Data has changed."
strMsg = strMsg & " Do you wish to save the changes?" & Chr(13)
strMsg = strMsg & "Click 'Yes' to Save or 'No' to Discard the changes."
Select Case MsgBox(strMsg, vbQuestion + vbYesNoCancel, "Save Record?")
Case Is = vbYes
Checkme = False
If Nxt = True Then
DoCmd.GoToRecord , , acNext
Nxt = False
End If
If Prv = True Then
DoCmd.GoToRecord , , acPrevious
Prv = False
End If
'MsgBox "Yes"
'do nothing
Case Is = vbNo
'MsgBox "No"
DoCmd.RunCommand acCmdUndo
CancelYes = False
Checkme = False
If Nxt = True Then
DoCmd.GoToRecord , , acNext
Nxt = False
End If
If Prv = True Then
DoCmd.GoToRecord , , acPrevious
Prv = False
End If
Case Is = vbCancel
'MsgBox "Cancel"
CancelYes = True
End Select
End If
If CancelYes = True Then
'MsgBox ("This will stop it from closing")
DoCmd.CancelEvent
CancelYes = False
End If
If Checkme <> True Then
If Nxt = True Then
DoCmd.GoToRecord , , acNext
Nxt = False
End If
If Prv = True Then
DoCmd.GoToRecord , , acPrevious
Prv = False
End If
End If
End Sub
Last edited: