newbie question: me.cmdNext vs cmdNext

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all

I've seen that to refer to a control, sometimes it is used the me. prefix, sometimes not, I can't understand if there is a rule and what's the purpose of this prefix
Any help very much appreciated

Kind Regards
max
 
max said:
Hi all,

I've seen that to refer to a control, sometimes it is used the me.
prefix, sometimes not, I can't understand if there is a rule and
what's the purpose of this prefix. Any help very much appreciated.

Kind Regards,
max

If you refer to a control just by its name, without any further
qualification, Access has to go through a search process to determine
what this reference is: is it a variable, is it a local property or
method, is it a global property or method, is it a control ... what is
it? Presumably there's a sequence of priority in which the
possibilities are interpreted, in case there are two objects in scope
with the same name. Using "Me" is a way of restricting the search to
the code object in which the current code is running; that is, the form
or report where the keyword is used.

The "Me" keyword is a reference to the current code object. So in code
behind a form, "Me" refers to the form containing the code. There are
two ways you're likely to see "Me" used: as "Me.something", and as
"Me!something". They mean different things, but most often Access
resolves them in such a way that it doesn't matter which you use.

Technically "Me.something" is used to refer to properties or methods of
the form, while "Me!something" is used to refer to members of the form's
Controls collection. However, wherever possible Access adds the
controls on the form and the fields in the form's recordset to its list
of properties, so you can usually get away with writing "Me.controlname"
as a reference to a control, or "Me.fieldname" as a reference to a
field. The only time you can't is when there is a true property of the
form with the same name; for example, "Me.Name" is always a reference
to the name of the form, even if there is a control on the form called
"Name". In such cases you must use the bang (!) operator to refer to
the control: "Me!Name".

People find it convenient to use the dot notation (Me.something), even
for controls, because the "intellisense" drop-down and autocomplete when
coding help you get the names right, and generate compile errors if you
get them wrong. So in that respect it's an aid to coding.
 
Dirk
many many thanks, this explaination is really helpful for me! I have several books for reference, but believe me none of them could give me such a clear explaination! :
Max
 
To expand slightly on Dirk's response, the (!) is used
prior to user assigned names and the (.) is used prior to
reserved names

eg) Forms!MyForm!txtMyControl.RecordSource

'MyForm' is name assigned to form by user.

'txtMyControl' is name assigned to control by user.

'RecordSource' is the reserved name of a control property.

-----Original Message-----
Hi all,

I've seen that to refer to a control, sometimes it is
used the me. prefix, sometimes not, I can't understand if
there is a rule and what's the purpose of this prefix.
 
Back
Top