What does Me! (or Me.) signify?

Rardac

New member
Local time
Today, 18:05
Joined
Jan 13, 2010
Messages
2
Hi all,

I borrowed the chunk of code below to perform a similar function on a form I was working with. I understood what the code was doing, but I thought that the Me! was just a placeholder for my own table names. When I used my own table names, however, I got a runtime error 2465. Then, when I used Me! as specified, the code worked perfectly...

I admit my Access skills are a bit rusty, but I don't recall seeing Me! or Me. used before. Can anyone explain how they work or point me to another source that might explain them? It would be much appreciated.

Thanks!


'************* Code Start **************
' This code was originally written by Erika Yoxall.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.'
' Code Courtesy of' Erika Yoxall'

Sub Zip_OnExit(Cancel As Integer)
Dim varState, varCity As Variant
varState = DLookup("State", "tblZipCode", "ZipCode =[Zip] ")
varCity = DLookup("City", "tblZipCode", "ZipCode =[Zip] ")
If (Not IsNull(varState)) Then Me![State] = varState
If (Not IsNull(varCity)) Then Me![City] = varCity
End Sub

************* Code End **************
http://www.mvps.org/access/
 
Last edited:
Quick google search on the meaning of Me! gives this link.

"Me!" refers to the current form, so when you use it like this:

Code:
Then Me![State] = varState

The code is saying, the current form and the state control = varState.
 
"Me!" refers to the current form, ...

Not quite. It refers to the current CLASS OBJECT. When used in a form module it refers to the form the module is attached to. When used in a REPORT module it refers to the report the module is attached to and when used in a class module it refers to that particular class.
 
I always get confused with CLASS objects.

I never use Form or Report Modules as in Access 1997, Modules were considered more efficient. Having converted everything including Macros to Modules, it is so much easier to manage the plethora of scripts that you would go back to Form or Report Modules as the scripts can be made to be Form or Report independent.

Do the Modules constitute a CLASS.

Simon
 
Thank you all for the responses and links - they were quite helpful.

The interesting thing is that the code in the form actually passes data to a table. I suspect that the code using Me! only worked because it was part of a bound text box (or a text box on a bound form). I'm not sure I would have gotten the same results on an unbound form. Any thoughts?
 

Users who are viewing this thread

Back
Top Bottom