Results 1 to 2 of 2
Thread: Confused about Me. (XP)
2003-08-22, 17:34 #1
- Join Date
- May 2002
- Thanked 0 Times in 0 Posts
Confused about Me. (XP)
Can Someone please explain why some VBA needs 'Me' before it and some don't. I've got the Microsoft Step-by-Step book for Access VBA, and it's got an example in it that I thought would need the 'Me' statement before it, but it doesn't and yet it works. Here's the code:
Private Sub FirstName_AfterUpdate() 'Copy the Firstname value to the Dear control
If IsNull(Dear) Then
Dear = FirstName
Why doesn't Dear need to be written as Me.Dear when the following statement DOES require 'Me'
Private Sub ContactTypeID_DblClick(Cancel As Integer)
On Error GoTo Err_ContactTypeID_DblClick
Dim lngContactTypeID As Long
If IsNull(Me![ContactTypeID]) Then
Me![ContactTypeID].Text = ""
lngContactTypeID = Me![ContactTypeID]
Me![ContactTypeID] = Null
In both instances, all the controls are on the same part of the Form, so I can't understand why the first one Does NOT require Me and the second one does????
Also, in the second example, the statement is written as . . .
Again, how come the first statement didn't need to be written as . . .
This is confusing me, and I'd really appreciate any help or explanation someone may have
Thanks in advance.
2003-08-22, 17:59 #2
- Join Date
- Mar 2002
- Thanked 30 Times in 30 Posts
Re: Confused about Me. (XP)
This can be rather confusing, you can use several ways of denoting controls almost interchangeably.
<UL><LI>If you refer to something without qualifying what it belongs to, VBA will try to resolve it. On a form or report, it will assume that it belongs to the form or report.
<LI>In a class module, Me refers to the instance of the class that is running the code.
<LI>A form or report acts as a class; the module behind the form or report is a class module, so Me refers to the form or report running the code.
<LI>The dot <big>.</big> is used to designate a property, while the bang <big>!</big> designates a member of a collection.
<LI>The default property of a form or report is its Controls collection. You don't need to name the default property explicitly.[/list]Are you still there? This means that the following expressions are all valid ways to refer to a text box named txtLastName:
In your first example, you could have used Me.Dear or Me!Dear instead of just Dear, and the second example should work as well with Me.ContactTypeID or even ContactTypeID instead of Me!ContactTypeID.