Setfocus to Null

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is it possible to set the focus of a form to Null from VBA? I have a form
that when it loads I would like to NOT have a control highlighted (ruins the
look).

Thanks in advance for your help.
 
Hi

I don't think you can do this using SetFous.

However, a good work around is to:

1. Create a new, unbound, text box.
2. Delete the box's label and set the background and border colours to
'transparent.
3. Set its Tab Index to 0 (zero)
4. Set its height and width properties to 0 (zero).

Having no width or height makes the text box invisible and, having the Tab
Index of 0, it takes the focus when the form opens which, of course you can't
see.

You just need to remember where you put the text box is it will be barely
visible (just a dot) in design view making it difficult to find if you want
to alter anything.

Note that you can't achieve this by simply creating a text box, setting its
tab index to zero and its visible property to false as non-visible contrals
cannot take the focus.

Sorted!

Good luck.

BW
 
You can do this by utilizing the SelStart and SelLen functions when the
first text control receives focus.
 
You just need to remember where you put the text box is it will be barely
visible (just a dot) in design view making it difficult to find if you want
to alter anything.

you can avoid this problem by *not* deleting the label "attached" to the
textbox control. just set the *label's* Visible property to False. you won't
see it in Form view - but it's still show in Design view, making the control
easier to find.

hth
 
Hi tina

No, your suggestion won't work as a control whose visible property is set to
false cannot receive the focus. Receiving the focus is the whole point of
this exercise!

Regards.

BW
 
Think about it BeWyched. A label, much less an attached
label can not receive the focus under any circumstances.
All tina was saying is that the label will be selectable in
DESIGN VIEW, making the text box easy to locate.

Another way to locate a zero height/width control in design
view is to to select it in the form's Object dropdown list.
 
Thanks Marsh - I did miss the point on that one.

Marshall Barton said:
Think about it BeWyched. A label, much less an attached
label can not receive the focus under any circumstances.
All tina was saying is that the label will be selectable in
DESIGN VIEW, making the text box easy to locate.

Another way to locate a zero height/width control in design
view is to to select it in the form's Object dropdown list.
--
Marsh
MVP [MS Access]

Hi tina

No, your suggestion won't work as a control whose visible property is set to
false cannot receive the focus. Receiving the focus is the whole point of
this exercise!

Regards.

BW
 
re-read my post, hon. i said "just set the *label's* Visible property to
False." the textbox control's LABEL, *not* the textbox control itself.

i use "hidden tabstop" textbox controls frequently in my forms, as needed,
and i always keep the control's label but make it invisible, so i can find
the textbox quickly in Design view.

hth
 
Wow. I've been trying to figure this out forever. What wonderful tidbits of
information you can find when you're looking for a solution to something else.

Thanks!
 
Back
Top