! or .

S

Scott

When entering code like
Me.Rabies.Visible = True
after typing the period (.) following Me a list appears that includes the
word Rabies (one of the fields I created). In looking at the online
guidance, I often see examples that seem to suggest that this be written as
Me!Rabies.visible = true; in this case nothing pops up after the ! but when I
press the period after Rabies I get a list and can choose 'visible'.

I think I once read that an exclamation mark should be used before
user-define/created fields and a period before Access pre-defined fields.
Can any of you 'real' programmers tell me if this makes a difference?
 
S

Sandra Daigle

Your definition is correct but many developers (myself included) prefer the
dot style notation. Do a google search for "Bang vs. Dot" and you'll find
tons of reading on the subject. I prefer the dot style reference primarily
for the ease of use (the intellisense) and because an incorrect dot style
reference will generate a syntax error while the other will cause a runtime
error.

Here is some links to get you started:

"Cleaner Coding: Bang vs. Dot "
http://www.advisor.com/Articles.nsf/aid/BAROA06

The Access Developer's Handbook (2000 and probably 2002) (Litwin, Getz,
Gilbert) also has a good discussion on this issue.
 
B

Bob Hairgrove

When entering code like
Me.Rabies.Visible = True
after typing the period (.) following Me a list appears that includes the
word Rabies (one of the fields I created). In looking at the online
guidance, I often see examples that seem to suggest that this be written as
Me!Rabies.visible = true; in this case nothing pops up after the ! but when I
press the period after Rabies I get a list and can choose 'visible'.

I think I once read that an exclamation mark should be used before
user-define/created fields and a period before Access pre-defined fields.
Can any of you 'real' programmers tell me if this makes a difference?

The difference is one of early vs. late binding. I usually use the "!"
(or "bang") operator for reading or writing to field values in the
form's underlying recordset, whereas I use the dot operator to refer
to the form's control names.

Your VBA code might compile just fine when you use the bang operator,
even if there is a mistake or typo somewhere, because Access cannot
resolve the name until runtime. Using the dot operator for controls,
however, will assure you that if the code compiles successfully, all
the references to the controls must be correct because those names are
resolved at compile-time. Unfortunately, Access cannot resolve field
names of the recordset at compile-time anyway because the form's
RecordSource might change later during runtime.

Therefore, the "bang" operator requires late binding, whereas the
"dot" operator does early binding. There are times when one version is
more desirable than the other, but I try to use early binding as often
as possible. And it always helps to name the controls something
different than the field name in the control source. Access (and the
developer <g>) can sometimes get them mixed up.
 
S

Scott

Perfect, and many thanks!
--
SHB


Sandra Daigle said:
Your definition is correct but many developers (myself included) prefer the
dot style notation. Do a google search for "Bang vs. Dot" and you'll find
tons of reading on the subject. I prefer the dot style reference primarily
for the ease of use (the intellisense) and because an incorrect dot style
reference will generate a syntax error while the other will cause a runtime
error.

Here is some links to get you started:

"Cleaner Coding: Bang vs. Dot "
http://www.advisor.com/Articles.nsf/aid/BAROA06

The Access Developer's Handbook (2000 and probably 2002) (Litwin, Getz,
Gilbert) also has a good discussion on this issue.

--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.

When entering code like
Me.Rabies.Visible = True
after typing the period (.) following Me a list appears that includes
the word Rabies (one of the fields I created). In looking at the
online guidance, I often see examples that seem to suggest that this
be written as Me!Rabies.visible = true; in this case nothing pops up
after the ! but when I press the period after Rabies I get a list and
can choose 'visible'.

I think I once read that an exclamation mark should be used before
user-define/created fields and a period before Access pre-defined
fields. Can any of you 'real' programmers tell me if this makes a
difference?
 
J

John Griffiths

.. or ! do the same thing.

.. relates to early binding, which is why intellisense works (the list of
properties).

! relates to late binding and is evaluated at runtime,
which is why an error like MyControl!NonExistantProperty is not caught
until the code is run.
! is also used in other situations where the VBA editor doesn't go, such
as macros.

I think ! started off as an operator returning an item from a collection so
that
CollectionName.Item("PropertyName") was equivalent to
CollectionName!PropertyName in AccessBasic,
think Forms! and Reports!.

Excel uses Application.ActiveSheet, ActiveCell, ActiveReport...
Access uses Screen.ActiveForm, ActiveControl, ActiveReport...

The other symbols [ ] are used to delineate a symbol to be evaluated at
runtime.

Of course I could be wrong - John
 

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