Rich1234 said:
Thanks guys. I'm still not too clear on how this all works (when to
use ! instead of .) I need to read up on this.... can you recommend?
Dirk - I'm a bit confused. What is the "subform control name" in
your first line of code? Is that just the name of the subform? (I
guess not - I tried this and it doesn't work. I don't know what this
"subform control name" is in my case.)
Baz- Thanks... I got it working using your suggestion
Dirk Goldgar said:
Hi
i have a main form with a save button. When this is pressed, a
subform appears (the save button's onclick event makes the form
visible.) I am having difficulty in setting the focus to the field
on the subform.
What is the code I need? I've tried these 2 lines together, as
listed: Me.subform name.Controls![field name].SetFocus
Me.Save_Vehicle.Visible = False
which isn't working... I get an error saying you can't hide a
control that has got the focus! Even when I have tried not hiding
the save button, the focus still isn't shifting. I must be doing
something wrong... please help. (just to reiterate, the save button
is on the main form.)
You have to set the focus both to the subform control (on the main
form), and to the control on the subform itself:
Me!SubformControlName.SetFocus
Me!NameOfControlOnSubform.SetFocus
Explanation: The main form has an "active control", and the form
object displayed in the subform control has its own "active
control". You need to make the main form's active control be the
subform, and you also need to make the subform's active control be
the one you want.
I actually made a mistake -- sorry. That second line should have been:
Me!SubformControlName!NameOfControlOnSubform.SetFocus
By "SubformControlName", I mean the name of the control on the main form
that displays the subform in its window. That may or may not be the
same as the name of the form object that is displayed in that window,
depending on how the subform control was created and whether you renamed
it. If you just click the "subform control" tool on the Controls
toolbar and and then click on the form, a new subform control will be
created and named something like "Subform1" (numbers increasing
according to the number of controls already on the form). But if you
drag a form object from the database window and drop it on the form, the
subform control will be created with the same name as that form object.
And if the form wizard creates the subform, it gives it a name based on
what you decide to call it.
By "NameOfControlOnSubform", I mean the name of the control *on the
subform* to which you want to SetFocus.
--
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)