Re: Bang vs. Dot - final answer



"Darryl Kerkeslager" <kerkeslager@xxxxxxxxxxx> wrote in message
news:BZydnTZqO-qTu6DeRVn-sA@xxxxxxxxxxxxxx

> 1. Compile does not pick up missing controls, i.e., if I have a reference
> to Me!btnEdit, and remove that button from my form, Compile will not show
> a warning. It *will* show a warning if I have referenced my control as
> Me.btnEdit.

An excellent reason to use the .dot. However, this is a double edged sword.
What happens if you change the reocrdsouce of a form, and then some of the
fields are NOT available.

me!SpecialID
me.SpeicalID

If you CHANGE the reocrdsouce of a form in code, then we can NOT compile, or
resolve the 2nd one (since, we can't know if there will in fact be a
SpecialID until AFTER we set the sql for the form). What this means is that
you must:

a) place a control on the form so that me.SpecialID will ALWAYS work
b) or start using the bang notation!

So, for fields like "id", and many other fields that you will NOT WANT to
place on the form, then you need to use the ! notation. (otherwise your code
will fail if you change the forms recordsouce).

So, while you gain in compile time checking, you loose the ability to
reference fields in the reocdset when you use dot (or, you are forced to
pile up a bunch of controls in the corner of the screen that only serve to
allow the "dot" notation to work). I can't tell you the number of times I
seen a access application with a WHOLE BUNCH of controls piled up in the
corner for JUST the reasons to use fields in the reocrdsouce. All of those
controls that are NOT being used for editing were ONLY there to serve to use
the "dot" notation. So, why pile up a bunch of controls that never get used
so you can use the 'dot' notation?

So, in place of have to put a whole bunch of un-used controls on the form,
why not use ! notation? (again, stress we are taking about when you change a
forms record source..but I find this happens more and more as my ms-access
skills improve).

For this reason, I have found the following trade off:

For things like "ID", and accessing fields of the reocrdsouce that will NOT
be on the form, or are NOT required to be on the screen, I now use the !
bang notation. Again, this rule is especially valuable if you have any code
that changes the reocrdsouce of a form.

>
> 2. Compile will not flag certain syntax errors - for instance, mistakenly
> typing Me!btnEdit.SetFocus = True
>
> Reason enough, I think, to always use the dot operator, even if it is not
> 'correct'.

Again, the above assumes you got a control called btnEdit. Since you ARE
setting the focus to a control, then you MOST certainly want to use "dot".
Again, in this example if you have a un-bound control called btnEdit, then
Me!btnEdit.SetFocus will NOT WORK!!! Again, in this case, it is clear that
the ! bang notation looks to the reocxreset, and then figures out that you
go a control with the same name. So, really, the rule should be that you
use 'dot' to refer to a control. The above example is bad, because it will
ONLY work if btnEdit is a BOUND control. What do you do for un-bound
controls? (! bang simply does not even work).

So, if you plan to use features of that control, (such as setting focus)
then of course you would use the ".dot". There is no final rule here, but
you are accessing, and setting focus to a control, and that requires you use
"dot". As mentioned, the ! notation will not even work for un-bound
controls, so it makes little sense to confuse the issue here.

So, for the sake of clarity, why adopt a rule where you use the 'dot'
notation when you NEED to use the actual control, and when you do NOT use
the actual control, then use the bang notion. For example

msgbox "company name is = " & me!CompnayName

If I go and delete the company name control on the form, the above code will
CONTINUE to operate. In other words, the above code will continue to
function if I delete some controls on the form. However, if your code RELIES
ON controls that MUST be on the form, then we should use the 'dot' notation,
as then deleting the control on the screen will be caught by the compiler
for you. Makes sense to me!! And, note the reverse:

if you did not need the controls, then if you used the ! bang notation and
delete the control on the screen, then your code will NOT fail!

So, if the above code is to RELY on the FACT of a complayName control on the
form, then I would use "dot". If the code dies NOT need to rely on the
control, then use bang.

Simply put, you as a developer can make a decision here on which one to use,
and that decision will make your resulting code more reliably, and will not
fail if you delete control. And, if done right, if you do delete a control,
then the compile will catch it in code that DOES requite the control.

So, don't just pick one blindly over the other. Pick the right notation that
will catch the right errors in your code!!


--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pleaseNOOSpamKallal@xxxxxxx
http://www.members.shaw.ca/AlbertKallal


.


Quantcast