Hi John,
It is also bad practice to have a control with the same name as a
built-in property. While you are correct that the bang syntax would
get you to the control rather than the property, it is still better
to have controls that are not named the same as built-in properties.
I am not crusading for the dot syntax over the bang syntax - I
simply prefer it. If you want to be precise then the best syntax is
probably the fully qualified reference (using the me keyword rather
than the full form reference). According to the Access 2000
Developers Handbook (Litwin, Getz and Gilbert), both bang and dot
styles are actually converted to the parentheses and quotes style of
reference - which is the style they recommend. Instead of
forms!frmMyForm!LastName or forms!frmMyForm.lastname they would
recommend Forms("frmMyForm")("lastName").
There is/was an excellent article by Andy Baron, "Cleaner Coding:
Bang vs. Dot" in the July 1999 issue of the Advisor Access - VB -
SQL magazine. (
www.advisor.com The article may still be available
online). After I read this article, I completely quit using the
bang (!) except in instances where it is absolutely required: in
queries that refer to a control on an open form and when refering to
a field
of a recordset (which could be avoided by using a fully qualified
reference through the fields collection but efficiency is the key -
mine and the CPU's).
The upshot of the article is that you can always refer to a form
control via the dot (.) because Access creates a property for every
control and for every recordset field. The benefit is that you get
syntax checking at compile time and you get the intellisense
dropdown list of properties that are available for the control you
are referencing. In later versions of Access you can get the
intellisense with the bang syntax but you have to hit Ctl-Spacebar
to activate it - just one more keystroke for my weary hands!). It's
a religious preference - not an absolute (especially if you know
and understand references - which you should anyway before you start
cranking out tons of code).
--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.
.... however with yours you cannot guarantee to get the "controls"
collection as the default is "properties". If there was a control
added named the same as a property your method would fail. It's just
good practice rather than something to spend hours debating. .
My reference
-------------------
me.frmsubform.form.CtlName
Your reference
-----------------------
me!frmsubform.form!CtlName
While your reference is valid, so is the one that I offered. Both
of these are correct references which in fact refer to the fully
qualified reference:
forms("MyForm").controls("frmsubform").form.controls("CtlName")
The bang vs. dot debate is well worn. I prefer the dot syntax
--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this
newsgroup.
JohnFol wrote:
To be accurate it should be
me!frmsubform.form!CtlName
To reference a control on the subform, you must also reference
the subform control. If the subform control is named frmsubform
and the control on the subform is named CtlName then from the
class module of the main form the correct reference to this
control would be:
'to assign a value
me.frmsubform.form.CtlName
Note that 'frmsubform' must be the name of the subform control on
the main form. This is not necessarily the same as the name of
the form object that is referenced in the ControlSource of the
subform control. To be sure, open the main form and click once
on the subform then check the name property under the Other tab.
Whatever you find there is what belongs in place of frmsubform.
--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this
newsgroup.
Alex H wrote:
Hi if i use the following to collect data from the current
record on a main form:
variable = me.fieldname
How do I collect data from the current record on the subform
please?
i used
variable = me.frmsubform.fieldname but that didn't wotj
thanks
Alex