Referring to Me
The Me keyword is like an implicitly declared variable; it's available to every procedure in a Form or Report module. Using Me is a great way to write generic code in a form or report. You can change the name of the form or report, and the code will be unaffected. Here's an example:Me.RecordSource = "qryProjects"
This code changes the RecordSource property of the current form or report to qryProjects.It's also useful to pass Me (the current form or report) to a generic procedure in a module, as shown in the following example:Call ChangeCaption(Me)
The ChangeCaption procedure looks like this:Sub ChangeCaption(frmAny As Form)
If IsNull(frmAny.Caption) Then
frmAny.Caption = "Form For - " & CurrentUser
Else
frmAny.Caption = frmAny.Caption & " - " & CurrentUser
End If
End Sub
The ChangeCaption procedure in a Code module receives any form as a parameter. It evaluates the caption of the form that was passed to it. If the caption is Null, ChangeCaption sets the caption to "Form For -", concatenated with the user's name. Otherwise, it takes the existing caption of the form passed to it and appends the user's name.