PDA

View Full Version : Solved: Subform Control



JustJerry
09-02-2005, 12:43 PM
What am I missing???

If Me.Ant2Qry_subform.Visible = False Then
DoCmd.GoToControl [LineQry subform].Form.Controls!WCTypeID
End If

The above code executes after a user checks the 'checkboxA' on my main form.

What is happening is that I get a error saying there is No Control "EWP63" on the subform [LineQry subform]. "EWP63" is the VALUE currently in the field WCTypeID. Why won't it just GO to the control, and WHY is it assigning a value to the control I am trying to go to??

On my subform, WCTypeID is a combo box that gets it's data from a qry, if this matters any.

Thank you for help,

Newbie Extraordinairehttp://vbaexpress.com/forum/images/smilies/037.gif

xCav8r
09-02-2005, 08:00 PM
Jerry, :hi:

You need to break it down into two steps: first go to the subform, then go to the control on the subform.

Private Sub GoToSubFormControl()
DoCmd.GoToControl Me.SubForm.Name
DoCmd.GoToControl "ControlName"
End Sub

Here's a link to an article that does the same thing but uses a macro instead:

http://support.microsoft.com/?kbid=209689

HTH! :whistle:

JustJerry
09-03-2005, 08:07 PM
Hiya XCav8R,

Ok, I couldn't get that to work. Here is what I have for VBA Code

Private Sub WGCX_AfterUpdate()

If Me.WGCX.Value = True Then
Me.LineQry_subform.Visible = True
If Me.Ant2Qry_subform.Visible = False Then
DoCmd.GoToControl Me.LineQry_subform.Name
DoCmd.GoToControl "WCTypeID"
End If
Else
Me.LineQry_subform.Visible = False
End If

End Sub

I'm trying to do this on the checkbox AfterUpdate. I now get an error saying that there is no Field named "WCTypeID" in current record. Yes, I've checked and checked the name, and don't get it.

As a test, I typed in the GoToControl command on another field in the same subform that contains the field "WCTypeID". I did it using the AfterUpdate option, and it DOES go to this field. SOmething about tying to get to it from the main form I am goofing up

I notice in your example you havePrivate Sub GoToSubFormControl(). Does this matter?

JustJerry
09-03-2005, 08:52 PM
GOT IT!! Although the total coding is unfinished, I did finally get the test phase part of it done. Here is what I ended up with.

Private Sub WGCX_AfterUpdate()

If Me.WGCX.Value = True Then
Me.LineQry_subform.Visible = True
If Me.Ant2Qry_subform.Visible = False Then
Me.LineQry_subform.SetFocus
Me.LineQry_subform.Form.WCTypeID.SetFocus
Me.LineQry_subform.Form.WCTypeID.Dropdown
End If
Else
Me.LineQry_subform.Visible = False
End If

End Sub