I created a action so that when I press the esc key it closes the form
however I have the following code in the form as well
so that whenever the form is closed it checks to see if data has changed and ask if that is what you want to do problem is that when I hit esc it closes the form and ignrs any changes that where made
but when I click on the close button or the button I created for close
it works fine any thoughts?
oh and Form.Refresh before cmd.close doesnt work
Code:
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyEscape Then
DoCmd.Close
End If
End Sub
Code:
Sub Form_Unload(Cancel As Integer)
On Error GoTo Form_Unload_Err
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
'MsgBox "Yes"
'do nothing
Case Is = vbNo
'MsgBox "No"
DoCmd.RunCommand acCmdUndo
CancelYes = False
Case Is = vbCancel
'MsgBox "Cancel"
CancelYes = True
End Select
End If
If CancelYes <> True Then
If ParentFormIsOpen() Then Forms![Employees1]!ToggleLink = False
Else
'MsgBox ("This will stop it from closing")
DoCmd.CancelEvent
CancelYes = False
End If
Form_Unload_Exit:
Exit Sub
Form_Unload_Err:
MsgBox Error$
Resume Form_Unload_Exit
End Sub
but when I click on the close button or the button I created for close
Code:
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
oh and Form.Refresh before cmd.close doesnt work