Results 1 to 6 of 6
  1. #1
    Join Date
    May 2006
    Posts
    30

    Unanswered: problems referencing subform controls

    My main form is Form3, subform is subTool2, the control I'm trying to
    reference is cboLayerType. The subform control on the main 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, tho it does find the name of the subform control). 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

  2. #2
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Paul

  3. #3
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    I am assuming the code is in the form module for Form3. I would recommend changing all of your references to the form to Me. Ex.:

    Form_Form3.subTool.cboLayerType to Me.subTool.cboLayerType

    It is faster to reference the form this way. Also, you only have to add one more bit to be able to get to the subform controls:

    Me.subTool.Form.cboLayerType

    You are missing the Form in all of your references.

  4. #4
    Join Date
    May 2006
    Posts
    30
    It still just will not find the controls on the subform..

  5. #5
    Join Date
    Aug 2002
    Location
    Melbourne, Australia
    Posts
    111
    Code:
    Form_subTool2.txtNumOfLayers.SetFocus
    Should be.
    Code:
    Me.subtool2.SetFocus
    Your must first reference the subform control on the main form first, then you can reference controls on the subform.

    To set focus on the subform and then go to a new record in the subform and then go to a control called Comment you would use;

    Code:
    Me.sfrmMySubForm.SetFocus
    
    DoCmd.GoToRecord , , acNewRec
    
    DoCmd.GoToControl "Comment"
    Code:
    Form_Form3.txtJobNum = "" Or IsNull(Form_Form3.txtJobNum) Then
    I would write as;

    Code:
    If isnull(Me.txtJobNum) or Me.txtJobNum = "" then
    and continue that method through all the code. If you use Me. I don't see the need for Form_Form3.

    If you have used the reference posted by pbaldy and you still can't get it to work then have a look at my attached doc. Somethime the name of the control on the main form is not the same as shown in Forms Tab.
    Regards,



    John A

  6. #6
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    i can't be bothered will all that .setfocus stuff
    illustration of another way to talk to subforms.

    izy
    currently using SS 2008R2

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •