How can I know when to use a "." or a "!"

  • Thread starter Thread starter Kelvin Beaton
  • Start date Start date
K

Kelvin Beaton

This one works,

=[Forms]![frm_Families]![frm_CaseNotes_subform].[Form].[noteid]



This one does not.

=[Forms]![frm_Families]![frm_CaseNotes_subform].[Form]![noteid]



MS Access Expression Builder created this one. It doesn't work either

Forms![frm_CaseNotes_subform]![NoteID]



How would I know to use a "." instead of a "!" ?



I'm using this string for the default value in a popup form so I can link
the records together...



Thanks



Kelvin
 
That looks backwards. The one you say doesn't work really should.

The difference between . and ! is
.. is to indicate a property or method of an object
! is to indicdate a user defined object.
You will note that Me. is used a lot. That is because Me is a shortcut to
refer to the current form or report and accepts either. Me! and Me. are the
same; however, most of us use Me. because when you are coding and use the .
you get a drop down of all the objects, properties, and methods associated
with the form. If you use ! you do not.

So,
=[Forms]![frm_Families]![frm_CaseNotes_subform].[Form].[noteid]
^
The form is user defined

=[Forms]![frm_Families]![frm_CaseNotes_subform].[Form].[noteid]
^
This is a user defined control on the form

=[Forms]![frm_Families]![frm_CaseNotes_subform].[Form].[noteid]
^
This is a form object of the subform. It
is not referred to
by name, but there is only one form bound
to the subform
control using the Source Object property.

=[Forms]![frm_Families]![frm_CaseNotes_subform].[Form].[noteid]

^
This is where I am
confused. I think the ! should
work because you are
referring to a user
defined object on the form.
 
Klatuu

The statement

" ...Me! and Me. are the same ..."

is not entirely correct. For example, if the Form's (or Report's) has a
Control "Name" (OK, we know to avoid it but new users don't) then:

Me.Name refers to the name of the Form

Me!Name refers to the (value of) the Control "Name".

Basically the Dot operator "." refer to a Property of the Object (Me, the
Form in this case) while the Bang operator "!" refers to an item in a
Collection.

When we use:

Me!Name

we actually take advantage of the *default* Property "Controls" of the Form.
The full syntax would have been

Me.Controls.Item("ControlName")

Using the Bang to refer to an item in the Controls and omit the explit
"Controls" since it is the default Property of Me / Form, we end up with

Me!ControlName

The confusing part is that Access automatically creates a (custom???)
Property for each Control on the Form (and Field in the RecordSource) using
the ControlName as the Property name whenever possible. This Property
refers to the same Control. Thus, when we use:

Me.ControlName

we actually use the Property automatically creates by Access to refer to the
Control.

In the example at the beginning, "Name" is already an inbuilt Property so
Access couldn't create a second Property "Name". This in this case, Me.Name
and Me!Name actually refer to 2 different things altogether.

There are a few good article on Bang vs Dot but I don't have them handy.
Search Google ... if you are interested.

--
HTH
Van T. Dinh
MVP (Access)



Klatuu said:
That looks backwards. The one you say doesn't work really should.

The difference between . and ! is
. is to indicate a property or method of an object
! is to indicdate a user defined object.
You will note that Me. is used a lot. That is because Me is a shortcut to
refer to the current form or report and accepts either. Me! and Me. are
the
same; however, most of us use Me. because when you are coding and use the
.
you get a drop down of all the objects, properties, and methods associated
with the form. If you use ! you do not.

So,
=[Forms]![frm_Families]![frm_CaseNotes_subform].[Form].[noteid]
^
The form is user defined

=[Forms]![frm_Families]![frm_CaseNotes_subform].[Form].[noteid]
^
This is a user defined control on the form

=[Forms]![frm_Families]![frm_CaseNotes_subform].[Form].[noteid]
^
This is a form object of the subform. It
is not referred to
by name, but there is only one form bound
to the subform
control using the Source Object property.

=[Forms]![frm_Families]![frm_CaseNotes_subform].[Form].[noteid]

^
This is where I am
confused. I think the ! should
work because you are
referring to a user
defined object on the
form.
Kelvin Beaton said:
This one works,

=[Forms]![frm_Families]![frm_CaseNotes_subform].[Form].[noteid]



This one does not.

=[Forms]![frm_Families]![frm_CaseNotes_subform].[Form]![noteid]



MS Access Expression Builder created this one. It doesn't work either

Forms![frm_CaseNotes_subform]![NoteID]



How would I know to use a "." instead of a "!" ?



I'm using this string for the default value in a popup form so I can link
the records together...



Thanks



Kelvin
 
Klatuu said:
That looks backwards. The one you say doesn't work really should.

The difference between . and ! is
. is to indicate a property or method of an object
Yes.

! is to indicdate a user defined object.

Not exactly. The "bang" operator indicates that what following is the
name of a member of a collection. E.g,

Me!txtMyTextbox

is the same as

Me.Controls!txtMyTextbox

which is the same as

Me.Controls("txtMyTextbox")
You will note that Me. is used a lot. That is because Me is a
shortcut to refer to the current form or report and accepts either.
Me! and Me. are the same

Not exactly, though in most cases they will come out the same.
 
Correct. Perhaps my explanation was a bit over simplified. Your post does,
however, point out one thing that, IMHO, is very important. That is the use
of good naming conventions. If you use them, you can't even accidently
create a naming conflict. It amazes me that not only does Microsoft ignore
this principle, many of their examples do not use them. This teaches bad
habits to new users.

Van T. Dinh said:
Klatuu

The statement

" ...Me! and Me. are the same ..."

is not entirely correct. For example, if the Form's (or Report's) has a
Control "Name" (OK, we know to avoid it but new users don't) then:

Me.Name refers to the name of the Form

Me!Name refers to the (value of) the Control "Name".

Basically the Dot operator "." refer to a Property of the Object (Me, the
Form in this case) while the Bang operator "!" refers to an item in a
Collection.

When we use:

Me!Name

we actually take advantage of the *default* Property "Controls" of the Form.
The full syntax would have been

Me.Controls.Item("ControlName")

Using the Bang to refer to an item in the Controls and omit the explit
"Controls" since it is the default Property of Me / Form, we end up with

Me!ControlName

The confusing part is that Access automatically creates a (custom???)
Property for each Control on the Form (and Field in the RecordSource) using
the ControlName as the Property name whenever possible. This Property
refers to the same Control. Thus, when we use:

Me.ControlName

we actually use the Property automatically creates by Access to refer to the
Control.

In the example at the beginning, "Name" is already an inbuilt Property so
Access couldn't create a second Property "Name". This in this case, Me.Name
and Me!Name actually refer to 2 different things altogether.

There are a few good article on Bang vs Dot but I don't have them handy.
Search Google ... if you are interested.

--
HTH
Van T. Dinh
MVP (Access)



Klatuu said:
That looks backwards. The one you say doesn't work really should.

The difference between . and ! is
. is to indicate a property or method of an object
! is to indicdate a user defined object.
You will note that Me. is used a lot. That is because Me is a shortcut to
refer to the current form or report and accepts either. Me! and Me. are
the
same; however, most of us use Me. because when you are coding and use the
.
you get a drop down of all the objects, properties, and methods associated
with the form. If you use ! you do not.

So,
=[Forms]![frm_Families]![frm_CaseNotes_subform].[Form].[noteid]
^
The form is user defined

=[Forms]![frm_Families]![frm_CaseNotes_subform].[Form].[noteid]
^
This is a user defined control on the form

=[Forms]![frm_Families]![frm_CaseNotes_subform].[Form].[noteid]
^
This is a form object of the subform. It
is not referred to
by name, but there is only one form bound
to the subform
control using the Source Object property.

=[Forms]![frm_Families]![frm_CaseNotes_subform].[Form].[noteid]

^
This is where I am
confused. I think the ! should
work because you are
referring to a user
defined object on the
form.
Kelvin Beaton said:
This one works,

=[Forms]![frm_Families]![frm_CaseNotes_subform].[Form].[noteid]



This one does not.

=[Forms]![frm_Families]![frm_CaseNotes_subform].[Form]![noteid]



MS Access Expression Builder created this one. It doesn't work either

Forms![frm_CaseNotes_subform]![NoteID]



How would I know to use a "." instead of a "!" ?



I'm using this string for the default value in a popup form so I can link
the records together...



Thanks



Kelvin
 

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

Back
Top