PC Review


Reply
Thread Tools Rate Thread

The Bang ! operator vs the . operator...

 
 
Rashar Sharro via AccessMonster.com
Guest
Posts: n/a
 
      15th Jun 2005
Hi,

What is the difference between the ! vs the . (period) in the following
statements:

Forms!frmMainForm!sfrSubForm!txtFieldName

Forms.frmMainForm.sfrSubForm.txtFieldName


Thanks,

Rashar

--
Message posted via http://www.accessmonster.com
 
Reply With Quote
 
 
 
 
Dirk Goldgar
Guest
Posts: n/a
 
      15th Jun 2005
"Rashar Sharro via AccessMonster.com" <(E-Mail Removed)>
wrote in message news:(E-Mail Removed)
> Hi,
>
> What is the difference between the ! vs the . (period) in the
> following statements:
>
> Forms!frmMainForm!sfrSubForm!txtFieldName
>
> Forms.frmMainForm.sfrSubForm.txtFieldName


The second one won't work; at least not in Access 97 through 2002,
though it's possible that Access 2003 might support it -- I can't say
for sure, but I doubt it. Both references work up to the subform:

Forms!frmMainForm!sfrSubForm
Forms.frmMainForm.sfrSubForm

but the control on the subform must be referenced with the bang, not the
dot.

Bang and dot have different meanings, but Access goes a long way to fix
things up so that either can be used in most situations. here's my
standard spiel on the two:

------ Bang vs. Dot in Control References ------
It's not so much a question of one or the other being "proper syntax",
but that they mean different things that nevertheless almost always give
the same result. As I understand it, the bang (!) notation specifically
denotes that what follows is a member of a collection; in this case, a
member of the form object's default collection, the Controls collection.
The dot (.) notation denotes that what follows is a property or method
of the preceding object. That would logically make the bang notation
"proper" and the dot notation improper.

But wait. Wherever possible, Access makes the controls on a form and
the fields in its recordsource all available as properties of the form.
It also makes the fields of the recordsource available via the bang
notation. I'm not sure exactly how it does this; maybe if a name is
not found in the Controls collection it checks the Fields collection of
the form's recordset as a fallback position. So for most practical
purposes Me!ControlName and Me.ControlName evaluate to the same thing,
and the timing tests I've seen suggest that there is little to choose
between them as far as execution efficiency is concerned. I seem to
recall that there is a very slight difference, but I can't remember
which way the advantage lies, and it's not much. There's a coding-time
advantage, however, to using the dot notation, as it makes the
"intellisense" dropdown lists available. That's a strong argument for
using the dot notation, in my book.

But wait again! I said above that Access makes the controls available
as properties "wherever possible". There are cases where it can't do
that. Specifically, it can't do it when there is already a property of
the same name as the control in question. For example, if your form
"Form1" has a control or a field foolishly named "Name", currently
displaying the value "John Doe", then executing this statement in the
form's code module:

Debug.Print Me!Name, Me.Name

will print

John Doe Form1

in the Immediate Window. So you must be careful not to use any reserved
words or built-in properties as names for your controls, if you want to
use the dot notation to refer to them. But then, you should avoid doing
that anyway, as it tends in general to confuse poor Access.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


 
Reply With Quote
 
Arvin Meyer
Guest
Posts: n/a
 
      15th Jun 2005
Neither will work. You need to add a reference to the Form property of the
subform control. Here are your alternatives:

Forms!frmMainForm!sfrSubForm.Form!txtFieldName

or

Forms.frmMainForm.sfrSubForm.Form.txtFieldName

or

Me.sfrSubForm.Form!txtFieldName

The first syntax is understood by Access and Jet. The second and third,
understood only by VBA. VBA also understands the first. The reference to Me
is from within the current form's (or report's) VBA module.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access Downloads
http://www.datastrat.com
http://www.mvps.org/access

"Rashar Sharro via AccessMonster.com" <(E-Mail Removed)> wrote
in message news:(E-Mail Removed)...
> Hi,
>
> What is the difference between the ! vs the . (period) in the following
> statements:
>
> Forms!frmMainForm!sfrSubForm!txtFieldName
>
> Forms.frmMainForm.sfrSubForm.txtFieldName
>
>
> Thanks,
>
> Rashar
>
> --
> Message posted via http://www.accessmonster.com



 
Reply With Quote
 
Dirk Goldgar
Guest
Posts: n/a
 
      15th Jun 2005
"Arvin Meyer" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)
> Neither will work. You need to add a reference to the Form property
> of the subform control.


Actually, at least in versions up to Access 2002, using the bang between
the subform reference and the name of the control on the subform will
work, without having to specify the Form property of the subform. I
have heard that Access 2003 is pickier about this, but I don't know if
under what circumstances.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


 
Reply With Quote
 
Jeff Boyce
Guest
Posts: n/a
 
      15th Jun 2005
Rashar

In addition to the other responders' descriptions:

With more recent versions of Access (including 2000), it is possible to get
something very like the Intellisense feature when you use the "!". This
allows you to type the following in your code-behind-form:

Me!txt

and then press <Ctrl>-<Spacebar> to see the list of all of the objects you
placed on your form that you named with the prefix "txt".

Why would you so-name your control? For one thing, to let you (and Access)
differentiate between the underlying field and the control that holds it.

Good luck!

Jeff Boyce
<Access MVP>

"Rashar Sharro via AccessMonster.com" <(E-Mail Removed)> wrote
in message news:(E-Mail Removed)...
> Hi,
>
> What is the difference between the ! vs the . (period) in the following
> statements:
>
> Forms!frmMainForm!sfrSubForm!txtFieldName
>
> Forms.frmMainForm.sfrSubForm.txtFieldName
>
>
> Thanks,
>
> Rashar
>
> --
> Message posted via http://www.accessmonster.com



 
Reply With Quote
 
Dirk Goldgar
Guest
Posts: n/a
 
      15th Jun 2005
"Jeff Boyce" <(E-Mail Removed)> wrote in message
news:e$%(E-Mail Removed)
>
> With more recent versions of Access (including 2000), it is possible
> to get something very like the Intellisense feature when you use the
> "!". This allows you to type the following in your code-behind-form:
>
> Me!txt
>
> and then press <Ctrl>-<Spacebar> to see the list of all of the
> objects you placed on your form that you named with the prefix "txt".


Whaddayaknow! I didn't know that, Jeff. Thanks for the tip.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


 
Reply With Quote
 
Rashar Sharro via AccessMonster.com
Guest
Posts: n/a
 
      15th Jun 2005
Thanks for all your input.

Greatly appreciated!

--
Message posted via http://www.accessmonster.com
 
Reply With Quote
 
fredg
Guest
Posts: n/a
 
      15th Jun 2005
On Wed, 15 Jun 2005 13:43:15 -0700, Jeff Boyce wrote:

> Rashar
>
> In addition to the other responders' descriptions:
>
> With more recent versions of Access (including 2000), it is possible to get
> something very like the Intellisense feature when you use the "!". This
> allows you to type the following in your code-behind-form:
>
> Me!txt
>
> and then press <Ctrl>-<Spacebar> to see the list of all of the objects you
> placed on your form that you named with the prefix "txt".
>
> Why would you so-name your control? For one thing, to let you (and Access)
> differentiate between the underlying field and the control that holds it.
>
> Good luck!
>
> Jeff Boyce
> <Access MVP>
>
> "Rashar Sharro via AccessMonster.com" <(E-Mail Removed)> wrote
> in message news:(E-Mail Removed)...
>> Hi,
>>
>> What is the difference between the ! vs the . (period) in the following
>> statements:
>>
>> Forms!frmMainForm!sfrSubForm!txtFieldName
>>
>> Forms.frmMainForm.sfrSubForm.txtFieldName
>>
>>
>> Thanks,
>>
>> Rashar
>>
>> --
>> Message posted via http://www.accessmonster.com


Thanks for posting this one Jeff.
In addition to Me!txt, etc., I notice that if you just type
Me! then ctrl+spacebar you get the whole list of Access and VBA
constants as well as all the Db objects, etc.
I keep forgetting the acDataErr constant spellings (or is it
acErrDataAdded? :-)) and now I can easily find the one I need.

--
Fred
Please only reply to this newsgroup.
I do not reply to personal email.
 
Reply With Quote
 
Graham Mandeno
Guest
Posts: n/a
 
      15th Jun 2005
"Jeff Boyce" <(E-Mail Removed)> wrote in message
news:e$%(E-Mail Removed)...
> Me!txt
>
> and then press <Ctrl>-<Spacebar> to see the list of all of the objects you
> placed on your form that you named with the prefix "txt".


Thanks for that, Jeff. This is very cool!

Consider yourself nominated for "Gem of the Week" :-)

Cheers,
Graham


 
Reply With Quote
 
=?Utf-8?B?QnJ1Y2VN?=
Guest
Posts: n/a
 
      16th Jun 2005
Why are so many useful features tucked away in some obscure corner of the
documentation? (Rhetorical question)
Thanks for pointing that out. I think it will save quite a few people a
fair amount of time.

"Jeff Boyce" wrote:

> Rashar
>
> In addition to the other responders' descriptions:
>
> With more recent versions of Access (including 2000), it is possible to get
> something very like the Intellisense feature when you use the "!". This
> allows you to type the following in your code-behind-form:
>
> Me!txt
>
> and then press <Ctrl>-<Spacebar> to see the list of all of the objects you
> placed on your form that you named with the prefix "txt".
>
> Why would you so-name your control? For one thing, to let you (and Access)
> differentiate between the underlying field and the control that holds it.
>
> Good luck!
>
> Jeff Boyce
> <Access MVP>
>
> "Rashar Sharro via AccessMonster.com" <(E-Mail Removed)> wrote
> in message news:(E-Mail Removed)...
> > Hi,
> >
> > What is the difference between the ! vs the . (period) in the following
> > statements:
> >
> > Forms!frmMainForm!sfrSubForm!txtFieldName
> >
> > Forms.frmMainForm.sfrSubForm.txtFieldName
> >
> >
> > Thanks,
> >
> > Rashar
> >
> > --
> > Message posted via http://www.accessmonster.com

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Like operator in VBA Dale Fye Microsoft Access VBA Modules 6 9th Dec 2009 08:08 PM
Not Like Operator AFSSkier Microsoft Access Queries 3 23rd May 2008 01:45 AM
Using a variable with the bang operator? =?Utf-8?B?Y3NlaWZmZXJseQ==?= Microsoft Access VBA Modules 1 4th Nov 2006 05:46 AM
generic problem with operator. compile error: operator * is not allowedon type T. SharpKnight Microsoft C# .NET 2 20th Feb 2006 01:08 PM
C# exponentiation operator & operator overloading David Laub Microsoft C# .NET 2 20th Dec 2003 09:30 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:56 AM.