how to point to a field

G

Guest

What is the best way to make a reference to a field?
I see a . or a ! in the code samples.
What is the difference between:

me.itemName or me.[itemName]

and

me!itemName or me![itemName]

Thank you!
 
G

Guest

Thank you!

Allen Browne said:
If you search you will find lots of articles on this.

Here's one:
http://doc.advisor.com/doc/05352

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

segurarl said:
What is the best way to make a reference to a field?
I see a . or a ! in the code samples.
What is the difference between:

me.itemName or me.[itemName]

and

me!itemName or me![itemName]

Thank you!
 
G

Guest

Although you may see even Microsoft documentation refer to a form control as
a field, it really is not. Fields are elements of tables and queries. It is
a good idea to use the terminology control to differentiate it from a field.

Now, to answer your question, the . identifies a property of method of an
access defined object. The ! identifies a user defined object.
Me is a shorthand identifier that refers to the current form or report.
Proper syntax would dictate using the ! after Me to refer to a control;
however, the shorhand allows the . to be used. Most of us will use the .
because during coding, it initiates the intellesence drop down, but ! does
not.

These are all actually the same:
me.itemName
me.[itemName]
me!itemName
me![itemName]

The fully qualified syntax would be.

| The user defined name for this form
V V The user defined name for this
control
Application.Forms!FormName!ControlName
^ A form is an Access Object

The square brackets are only really needed if the name contains spaces or
other non standard characters or the name is the same as an Access reserved
word. Names should only contain letters, numbers, and the underscore and
should not be reserved words (Date, Name, Time, Description, etc.)

Another good practice is to use naming conventions that make it immediately
clear what the control is. Using a prefix on the names is a common way to do
that. Just to list a few:
cbo - Combo Box
lst - List Box
txt - Text Box
cmd - Command Button
opg - Option Group
chk - Check Box
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top