SetFocus to a control on a subform

  • Thread starter Thread starter Steve W
  • Start date Start date
S

Steve W

I am having trouble setting the focus to a control on a subform with code in
the on exit event for a control in the main form.

Me.NameofControltoSetFocusto.SetFocus is not specific enough / does
not work


thanks for the help

Steve Wilson
 
To add to what Dan suggested ---

When going from the main form to the subform, you need to first set focus on the
subform control and then set focus on the control on the subform. Like:

Me.NameOfSubFormControl.SetFocus
Me.NameOfSubFormControl.Form.NameOfControl.SetFocus


--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
(e-mail address removed)
www.pcdatasheet.com
 
To set focus to a control on a subform, first set focus to the subform
control itself, and then the control on the subform:

Me.SubformControlName.SetFocus
Me.SubformControlName.Form.NameofControltoSetFocusto.SetFocus

where SubformControlName is the name of the control that holds the subform.
 
Let me jump in here...
I have a similar situation, and I was able to set focus
using the code you have below. But it seems to set focus
to the TOP row of data in a subform (i.e., if you're
using the subform to display several related records).
But I want to set focus to possibly the third or sixth
row (i.e., related record). I don't see how to set focus
on anything but the top row. I'm thinking "array" here,
but am not really sure...

Thanks,
Jonathan Mulder
 
Jonathan Mulder said:
Let me jump in here...
I have a similar situation, and I was able to set focus
using the code you have below. But it seems to set focus
to the TOP row of data in a subform (i.e., if you're
using the subform to display several related records).
But I want to set focus to possibly the third or sixth
row (i.e., related record). I don't see how to set focus
on anything but the top row. I'm thinking "array" here,
but am not really sure...

So how do you know which record you want to make current? That's really
what you're doing in this case -- navigating to a specific record. If
you have the primary key of the record, you can use a variety of
techniques to find it. If you want to go to a specific record number,
well, that really isn't a meaningful concept in a relational database,
but you can in fact go to records by number. If you want to go to the
last record, or to the "new" (blank) record, that's equally available.

Most of these things can be done by navigating in the subform's
recordset or recordsetclone, or by setting the focus to the subform and
then executing the DoCmd.GoToRecord method, as in

Me.sfSubform.SetFocus
DoCmd.GoToRecord acActiveDataObject, , acLast
 
Dirk,

Thank you very much for the helpful advice! The
DoCmd.GoToRecord worked great! You see, I wanted to go
to a specific "child record" (rather than the top "child
record" because I'm running a data check routine and want
to focus back on the data in the record does not pass the
data check. I appreciate your help!
 
Back
Top