Hi
I have the following code in most of my forms when exiting.
I'm currently tidying, formatting and commenting all of the code in my database and thought it would be cleaner to add this as a public sub in a module and then call it from each form. However, it doesn't like the 'Me' keyword and I'm struggling to make sense of the solutions I have found online.
Any suggestions greatly appreciated.
Kind Regards
Allison
I have the following code in most of my forms when exiting.
Code:
Private Sub ExitComms_Click()
On Error GoTo ErrorHandler
Dim ctl As Control
'If record is changed do you want to save changes
If Me.Dirty Then
If MsgBox("Do you want to save changes?", vbYesNo + vbQuestion, _
"Save") = vbNo Then
'If not, undo changes and close
Me.Undo
DoCmd.Close
'Otherwise save changes, confirm and close
Else
Me.Dirty = False
MsgBox "Changes saved"
DoCmd.Close
End If
'If no changes made close record
Else
DoCmd.Close
End If
Exit Sub
ErrorHandler:
Dim msg As String
msg = Err.Number & ":" & Err.Description
MsgBox msg
End Sub
I'm currently tidying, formatting and commenting all of the code in my database and thought it would be cleaner to add this as a public sub in a module and then call it from each form. However, it doesn't like the 'Me' keyword and I'm struggling to make sense of the solutions I have found online.
Any suggestions greatly appreciated.
Kind Regards
Allison