move to control

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

Guest

with this line:

DoCmd.GoToControl Me.Controls(frm).Form.Controls(0).Name

I would like to move to the first control on a subform (frm, previously
set). I get a type mismatch when trying to execute this. What's the correct
syntax?

Thanks
 
Try setting the focus first to the subform

Me.[Sub form name].setfocus
DoCmd.GoToControl Me.Controls(frm).Form.Controls(0).Name
 
smk23 said:
with this line:

DoCmd.GoToControl Me.Controls(frm).Form.Controls(0).Name

I would like to move to the first control on a subform (frm,
previously set). I get a type mismatch when trying to execute this.
What's the correct syntax?

Is [frm] a string variable, or an object? It should be a string, the
name of the subform control on the main form (which may or may not be
the same as the name of the form object it displays).

Calling the SetFocus method of the control in question is morte precise,
though. Also you have to move the focus both to the subform, and to the
control on the subform, separately. So I'd recommend something like
this:

Dim strSubform As String
strSubform = "YourSubformName"

' ...

With Me.Controls(strSubform)
.SetFocus
.Form.Controls(0).SetFocus
End With

That assumes, of course, the the first control in the subform's Controls
collection is one that can receive the focus -- not a label, for
example.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top