Connecting Tech Pros Worldwide Forums | Help | Site Map

The best (correct?) way

Geir Baardsen
Guest
 
Posts: n/a
#1: Nov 13 '05
Hi!
What is the best (correct?) way to do:

Me.txtCustID.SetFocus

in the OnLoad or in the OnOpen or... of the form?

Trevor Best
Guest
 
Posts: n/a
#2: Nov 13 '05

re: The best (correct?) way


Geir Baardsen wrote:
[color=blue]
> Hi!
> What is the best (correct?) way to do:
>
> Me.txtCustID.SetFocus
>
> in the OnLoad or in the OnOpen or... of the form?[/color]

Set it's TabIndex property to 0 in design view, forget the code. IT will
have the focus when the form is opened.

If however txtCustID is in the form header or footer then use some code
in OnOpen.

BTW your syntax is little off, the dot is for properties and methods,
use a bang for your objects, e.g.

Me!txtCustID
Me("txtCustID") which is short for
Me.Controls("txtCustID")

There used to be a little rule, if MS created it, it was Me. else if you
created it it was Me!

Using Me.ControlName can cause problems, if an object has the same name
as a property or method it can create confusion, either produce
unexpected results or just confuse a developer later on who looks at the
code. Additionally, it can produce random compile errors, one minute it
compiles OK the next it doesn't.
Keith Wilby
Guest
 
Posts: n/a
#3: Nov 13 '05

re: The best (correct?) way


Trevor Best <nospam@localhost> wrote:
[color=blue]
> Using Me.ControlName can cause problems, if an object has the same name
> as a property or method it can create confusion, either produce
> unexpected results or just confuse a developer later on who looks at the
> code. Additionally, it can produce random compile errors, one minute it
> compiles OK the next it doesn't.[/color]

That's interesting. I always use Me.ControlName but all my control names
have prefixes such as 'txt' (text box) and 'cbo' (combo box) - is this
relatively safe? I don't seem to get any compile errors. A97 BTW.
Allen Browne
Guest
 
Posts: n/a
#4: Nov 13 '05

re: The best (correct?) way


That's safe, Keith.

I use the dot, and don't bother with the prefix for bound controls (i.e. the
control has the same name as the field).

The only problem I've seen is when the field is *not* represented by a
control on the form, and you refer to the field as:
Me.MyField
That case can (but does not always) trigger the strange issue that Trevor
refers to.

It seems that the field-without-control is of the undocumented type
AccessField, and there must be some bugs in the way it is implemented. A
possibly related case can cause Access 2002 to crash (and possibly 2003).
That can happen where the LinkChildFields property of a subform control
refers to an AccessField type (i.e. a field in the subform's RecordSource,
that is not represented by a text box in the subform). Adding a text box for
this foreign key field stops the crashes.

BTW, the reason I prefer the dot is that if I mistype the control name, it
is caught at compile time.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Keith Wilby" <keith.wilby@AwayWithYerCrap.com> wrote in message
news:Xns954B5B6D5E503keithwilby@10.15.188.42...[color=blue]
> Trevor Best <nospam@localhost> wrote:
>[color=green]
>> Using Me.ControlName can cause problems, if an object has the same name
>> as a property or method it can create confusion, either produce
>> unexpected results or just confuse a developer later on who looks at the
>> code. Additionally, it can produce random compile errors, one minute it
>> compiles OK the next it doesn't.[/color]
>
> That's interesting. I always use Me.ControlName but all my control names
> have prefixes such as 'txt' (text box) and 'cbo' (combo box) - is this
> relatively safe? I don't seem to get any compile errors. A97 BTW.[/color]


Trevor Best
Guest
 
Posts: n/a
#5: Nov 13 '05

re: The best (correct?) way


Keith Wilby wrote:[color=blue]
> Trevor Best <nospam@localhost> wrote:
>
>[color=green]
>>Using Me.ControlName can cause problems, if an object has the same name
>>as a property or method it can create confusion, either produce
>>unexpected results or just confuse a developer later on who looks at the
>>code. Additionally, it can produce random compile errors, one minute it
>>compiles OK the next it doesn't.[/color]
>
>
> That's interesting. I always use Me.ControlName but all my control names
> have prefixes such as 'txt' (text box) and 'cbo' (combo box) - is this
> relatively safe? I don't seem to get any compile errors. A97 BTW.[/color]

Upgrade it to 2K2 and watch :-)

--

\\\\\\
\\ \\ Windows is searching
\ \ For your sig.
\ \ Please Wait.
\__\

Keith Wilby
Guest
 
Posts: n/a
#6: Nov 13 '05

re: The best (correct?) way


Trevor Best <nospam@localhost> wrote:
[color=blue][color=green]
>> That's interesting. I always use Me.ControlName but all my control
>> names have prefixes such as 'txt' (text box) and 'cbo' (combo box) -
>> is this relatively safe? I don't seem to get any compile errors. A97
>> BTW.[/color]
>
> Upgrade it to 2K2 and watch :-)[/color]

I've just done a test upgrade to A2003 and all seems well but I will bear
what you have said in mind :o)
Keith Wilby
Guest
 
Posts: n/a
#7: Nov 13 '05

re: The best (correct?) way


"Allen Browne" <AllenBrowne@SeeSig.Invalid> wrote:
[color=blue]
> BTW, the reason I prefer the dot is that if I mistype the control name,
> it is caught at compile time.[/color]

Being rather lazy I too prefer the dot as the code screen's auto-complete
saves a lot of typing. Thanks for your response.
Ima Lostsoul
Guest
 
Posts: n/a
#8: Nov 13 '05

re: The best (correct?) way


In article <4125a962$0$1494$afc38c87@auth.uk.news.easynet.net >,
nospam@localhost says...[color=blue]
> Geir Baardsen wrote:
>[color=green]
> > Hi!
> > What is the best (correct?) way to do:
> >
> > Me.txtCustID.SetFocus
> >
> > in the OnLoad or in the OnOpen or... of the form?[/color]
>
> Set it's TabIndex property to 0 in design view, forget the code. IT will
> have the focus when the form is opened.
>
> If however txtCustID is in the form header or footer then use some code
> in OnOpen.
>
> BTW your syntax is little off, the dot is for properties and methods,
> use a bang for your objects, e.g.
>
> Me!txtCustID
> Me("txtCustID") which is short for
> Me.Controls("txtCustID")
>
> There used to be a little rule, if MS created it, it was Me. else if you
> created it it was Me!
>
> Using Me.ControlName can cause problems, if an object has the same name
> as a property or method it can create confusion, either produce
> unexpected results or just confuse a developer later on who looks at the
> code. Additionally, it can produce random compile errors, one minute it
> compiles OK the next it doesn't.
>[/color]


If you use a good naming convention you will never have that issue.
Trevor Best
Guest
 
Posts: n/a
#9: Nov 13 '05

re: The best (correct?) way


Keith Wilby wrote:
[color=blue]
> Trevor Best <nospam@localhost> wrote:
>
>[color=green][color=darkred]
>>>That's interesting. I always use Me.ControlName but all my control
>>>names have prefixes such as 'txt' (text box) and 'cbo' (combo box) -
>>>is this relatively safe? I don't seem to get any compile errors. A97
>>>BTW.[/color]
>>
>>Upgrade it to 2K2 and watch :-)[/color]
>
>
> I've just done a test upgrade to A2003 and all seems well but I will bear
> what you have said in mind :o)[/color]

I have just done a A97 to 2K2 conversion for a rather old app we just
dug up out of the archives (it was a bespoke development for someone
long since gone but someone has expressed an interest in it) and apart
from where MS had introduced some functions/properties/methods that I
already had those names as functions it compiled OK. It's only when I
started working on a particular form that the compile errors started to
crop up. It may have been the AccessField thing that Allen mentioned but
I didn't check the field names vs textboxes as the primary concern was
to get the thing into a state where it can be shown to a prospective
client and *look* good, don't care if it works or not, as long as no
silly error messages pop up, if we get the job we'll worry about making
it work then :-) By then it will have been thoroughly tested and debugged.

--

\\\\\\
\\ \\ Windows is searching
\ \ For your sig.
\ \ Please Wait.
\__\

Trevor Best
Guest
 
Posts: n/a
#10: Nov 13 '05

re: The best (correct?) way


Ima Lostsoul wrote:
[color=blue]
> If you use a good naming convention you will never have that issue.[/color]

I totally agree, languages of old would never let you use a name that
conflicted with a reserved word but these new fangled things like Access
allow this sort of thing, even spaces in names which is {user
friendly|sloppy}. IMHO the language/platform would be doing the
developer more favors if it were a little bit more strict.

--

\\\\\\
\\ \\ Windows is searching
\ \ For your sig.
\ \ Please Wait.
\__\

David W. Fenton
Guest
 
Posts: n/a
#11: Nov 13 '05

re: The best (correct?) way


Keith Wilby <keith.wilby@AwayWithYerCrap.com> wrote in
news:Xns954B6653DB45Akeithwilby@10.15.188.42:
[color=blue]
> "Allen Browne" <AllenBrowne@SeeSig.Invalid> wrote:
>[color=green]
>> BTW, the reason I prefer the dot is that if I mistype the control
>> name, it is caught at compile time.[/color]
>
> Being rather lazy I too prefer the dot as the code screen's
> auto-complete saves a lot of typing. Thanks for your response.[/color]

Ctrl-Spacebar gets you a different version of Intellisense that
includes what you need. So, there's no extra typing with the bang.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Trevor Best
Guest
 
Posts: n/a
#12: Nov 13 '05

re: The best (correct?) way


David W. Fenton wrote:
[color=blue]
> Ctrl-Spacebar gets you a different version of Intellisense that
> includes what you need. So, there's no extra typing with the bang.[/color]

But it gives you a load of irrelevant entries to choose from.

--

\\\\\\
\\ \\ Windows is searching
\ \ For your sig.
\ \ Please Wait.
\__\

Geir Baardsen
Guest
 
Posts: n/a
#13: Nov 13 '05

re: The best (correct?) way


Trevor Best <nospam@localhost> wrote in message news:<4126378f$0$374$afc38c87@auth.uk.news.easynet .net>...[color=blue]
> Ima Lostsoul wrote:
>[color=green]
> > If you use a good naming convention you will never have that issue.[/color]
>
> I totally agree, languages of old would never let you use a name that
> conflicted with a reserved word but these new fangled things like Access
> allow this sort of thing, even spaces in names which is {user
> friendly|sloppy}. IMHO the language/platform would be doing the
> developer more favors if it were a little bit more strict.[/color]
[color=blue][color=green]
>>Thanks for information. You are right...I had some crashes now and[/color][/color]
then, and >>maybe it is because of wrong use of .DOTS and !BANGS[color=blue][color=green]
>>I'll check my entire projects...;-}[/color][/color]
David W. Fenton
Guest
 
Posts: n/a
#14: Nov 13 '05

re: The best (correct?) way


Trevor Best <nospam@localhost> wrote in
news:412667ba$0$21556$afc38c87@auth.uk.news.easyne t.net:
[color=blue]
> David W. Fenton wrote:
>[color=green]
>> Ctrl-Spacebar gets you a different version of Intellisense that
>> includes what you need. So, there's no extra typing with the
>> bang.[/color]
>
> But it gives you a load of irrelevant entries to choose from.[/color]

If you're going to point and click your way, yes.

But if you know how to TYPE, one or two characters gets you where
you need to be.

Personally, I don't experience any difference between the standard
Intellisense lists and the one that comes up with Ctrl-Space,
because I'm typing. Indeed, I prefer the Ctrl-Space list, since it
doesn't pop up when I don't want it.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Trevor Best
Guest
 
Posts: n/a
#15: Nov 13 '05

re: The best (correct?) way


David W. Fenton wrote:
[color=blue]
> Trevor Best <nospam@localhost> wrote in
> news:412667ba$0$21556$afc38c87@auth.uk.news.easyne t.net:
>
>[color=green]
>>David W. Fenton wrote:
>>
>>[color=darkred]
>>>Ctrl-Spacebar gets you a different version of Intellisense that
>>>includes what you need. So, there's no extra typing with the
>>>bang.[/color]
>>
>>But it gives you a load of irrelevant entries to choose from.[/color]
>
>
> If you're going to point and click your way, yes.
>
> But if you know how to TYPE, one or two characters gets you where
> you need to be.
>
> Personally, I don't experience any difference between the standard
> Intellisense lists and the one that comes up with Ctrl-Space,
> because I'm typing. Indeed, I prefer the Ctrl-Space list, since it
> doesn't pop up when I don't want it.
>[/color]

I would find it more useful if you could customise the order or if it
remembered your most used entries and stuck at the top of the list or
something, getting to ".Value" you have to type nearly the whole word
anyway to get past .ValidationRule, etc.

A good way would be type . to pring up your favorites, ctrl-space to
bring up all relevant and ctrl-space again to bring them all up

--

\\\\\\
\\ \\ Windows is searching
\ \ For your sig.
\ \ Please Wait.
\__\

Keith Wilby
Guest
 
Posts: n/a
#16: Nov 13 '05

re: The best (correct?) way


"David W. Fenton" <dXXXfenton@bway.net.invalid> wrote:
[color=blue]
> Ctrl-Spacebar gets you a different version of Intellisense that
> includes what you need. So, there's no extra typing with the bang.[/color]

Didn't know that. There's always summat new to learn - thanks :o)
Closed Thread