Problems referencing controls on subform

S

Seren

My main form is Form3, subform is subTool2, the control I'm trying to
reference is cboLayerType. The subform control on the mail form is named
subTool. For some reason, when I try to use the following code, it just will
NOT allow cboLayerType or txtNumOfLayers or ToolNum (all of the controls on
the subform I'm trying to reference). It's not in the list to select it. I
cannot figure out why. Anyone got any suggestions for me? Help would be
greatly appreciated!

Thanks!
Seren


If Form_Form3.txtJobNum = "" Or IsNull(Form_Form3.txtJobNum) Then
MsgBox "Please enter a job number"
txtJobNum.SetFocus
ElseIf Form_Form3.subTool.cboLayerType = "" Or
IsNull(Form_Form3.subTool.cboLayerType) Then
MsgBox "Please choose a Layer Type"
cboLayerType.SetFocus
ElseIf Form_Form3.subTool.txtNumOfLayers = 0 Or
IsNull(Form_Form3.subTool.txtNumOfLayers) Then
MsgBox "Please enter number of layers for this job"
Form_subTool2.txtNumOfLayers.SetFocus
ElseIf IsNull(Form_Form3.subTool.ToolNum) Or Len(Form_Form3.subTool.ToolNum)
= 0 Then
' Trim(ToolNum.Text) = "" Then
MsgBox ("You must enter a tool number")
Form_subTool2.txtToolNum.SetFocus
Else
stDocName = "frmLayer2"
DoCmd.OpenForm stDocName, , , stLinkCriteria
' DoCmd.OpenForm stDocName, , , JobID = Form_Form3.JobID
End If
 
D

Douglas J Steele

You need to recognize that there's a difference between a form being used as
a subform, and the control on the parent form that contains the subform.

If you created the subform by dragging subTool2 onto Form3, then odds are
that the control on Form3 is named subTool2. If you created the subform by
adding a subform control from the toolbox to Form3, then provided the
required information (either manually or using the wizard), the control will
likely be named something like Child1 (where the number will vary)

If the subform control's name is subTool2, try:

Form_Form3!subTool2.Form!ToolNum

or

Form_Form3.subTool2.Form.ToolNum

Otherwise, replace subTool2 above with whatever the subform control is
named.
 
S

Seren

I know that there is a difference between the name of the form used as the
subform and the actual subform *control*. The subform *control* name is
subTool. I have checked several times. That is what I used in the code. It
recongnizes subTool in the drop-down "autocomplete" box, but none of the
controls within the subform...
--
Always behave like a duck- keep calm and unruffled on the surface but paddle
like the devil underneath.


Douglas J Steele said:
You need to recognize that there's a difference between a form being used as
a subform, and the control on the parent form that contains the subform.

If you created the subform by dragging subTool2 onto Form3, then odds are
that the control on Form3 is named subTool2. If you created the subform by
adding a subform control from the toolbox to Form3, then provided the
required information (either manually or using the wizard), the control will
likely be named something like Child1 (where the number will vary)

If the subform control's name is subTool2, try:

Form_Form3!subTool2.Form!ToolNum

or

Form_Form3.subTool2.Form.ToolNum

Otherwise, replace subTool2 above with whatever the subform control is
named.
 
D

Douglas J Steele

You must have missed the .Form I added in what I posted.

Since you're referring to the subform control, you need to get to the form
that's contained in that control before you can start looking for controls
on the subform.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Seren said:
I know that there is a difference between the name of the form used as the
subform and the actual subform *control*. The subform *control* name is
subTool. I have checked several times. That is what I used in the code. It
recongnizes subTool in the drop-down "autocomplete" box, but none of the
controls within the subform...
 
S

Seren

This is really strange. At this point: Form_Form3!subTool.Form!txt the
dropdown consists of the controls in Form3, *not* for the subTool subform
control...
 

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

Similar Threads

second form opens w/ no records 1
Error on first keystroke 4
problems linking forms 0
Creating a function? 16
Searching in Result set 0
Help with IF Statement 3
Trigger an Insert on a Subform 14
Will this IF work? 6

Top