Setfocus in a field on a subform

  • Thread starter Thread starter Dave
  • Start date Start date
D

Dave

I thought I had asked this before but can not find my post.

when I open a form that contains a subform I want focus to be on a fields on
the subform.

this is what I have tried:

On the open event of the sub

me.subName!FieldName.setfocus

works if I ONLY open the subform - but does not work if I open the
main form

on the open even of the Main form

me.frmMain!subName!FieldName.setfocus
me.subName!FieldName.setfocus
me.FieldName.setfocus

None of them work

What am I doing wrong

Thanks

dave
 
Dave,
you need the correct syntax to refer to the subform
Often it is best done in 2 steps, first set focus to the subform control,
then to the control you want.

Me.SubformControlName.SetFocus
Me.SubformControlName.Form.ControlName.SetFocus

note that the SubformControl is separate from the subform that is inside it.
The SubformControl often has a different name from the subform.

Jeanette Cunningham
 
I follow the 2 steps process and it makes sense
However not sure I follow/understand "subformControl"
How would I know/find the name to that if it is not the subform name

Thanks for the reply

dave
 
Dave,
open the parent form in design view.
Click only once on the subform - you should see black handles around the
edge of it - the same as if you clicked a textbox, combo, image control etc.
Then click on it again, the black handles disappear.

The black handles are on the edge of the subform control.
The second click takes you into the subform itself.

Click on the main form then click once on the subform control and see the
black handles.
Look on the Other tab and find the name of the subform control.
It might be called Child followed by a number, or it may have a different
name.
Have a look on the property dialog on the Data tab, you should see Source
Object at the top of the list.
The Source Object gives you the name of the form that is currently in the
subform control.

You can swap different subforms into the same subform control ( more
advanced stuff)

Jeanette Cunningham
 
Thanks - finally got it working.
Had a field on the main form that was grabbing all the attention :)

dave
 
Back
Top