Results 1 to 8 of 8
  1. #1
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,877
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How Many Items In Sub Form? (a2k (9.0.6926) SP-3 Jet 4.0 SP-8)

    I have a Form (Order Header) and Sub Form (Order Details)

    When in the Form portion what is the code to determine the number of detail lines?

    Thanks, John

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: How Many Items In Sub Form? (a2k (9.0.6926) SP-3 Jet 4.0 SP-8)

    Put a text box txtCount on the subform with control source
    <code>
    =Count()
    </code>
    This text box can be hidden (Visible = No). You can refer to this text box in the control source of a text box on the main form:
    <code>
    =[SubformName]![txtCount]
    </code>
    You can also refer to these text boxes in code. Alternatively, you can use SubformName.Form.Recordset.RecordCount.

  3. #3
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,877
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How Many Items In Sub Form? (a2k (9.0.6926) SP-3 Jet 4.0 SP-8)

    Thanks for that information

    This Order Entry Form has an Add button when clicked takes me to a blank record (if new order) or first item (from previous line item entry) in the Sub Form.

    What code would I need behind the Add button to take the focus to the next blank record if there were existing line item records already in the Sub Form.

    Thanks, John

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: How Many Items In Sub Form? (a2k (9.0.6926) SP-3 Jet 4.0 SP-8)

    Do you want to set focus to the blank record in the subform, or to the blank record in the main form?

  5. #5
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,877
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How Many Items In Sub Form? (a2k (9.0.6926) SP-3 Jet 4.0 SP-8)

    I want to return to the next blank record in the subform.

    If the Sub Form is empty it will go to the first blank record which it does now.

    I there are records in the Sub Form it will go to the first blank record after the existing records.

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: How Many Items In Sub Form? (a2k (9.0.6926) SP-3 Jet 4.0 SP-8)

    Something like this, with the appropriate names substituted?

    Private Sub cmdAdd_Click()
    Me.SubformName.SetFocus
    If Not Me.SubformName.Form.NewRecord Then
    RunCommand acCmdRecordsGoToNew
    End If
    End Sub

  7. #7
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,877
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How Many Items In Sub Form? (a2k (9.0.6926) SP-3 Jet 4.0 SP-8)

    Outstanding!

  8. #8
    Lounger
    Join Date
    Nov 2002
    Location
    Farnborough, Hampshire, England
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How Many Items In Sub Form? (a2k (9.0.6926) SP

    <hr>You can also refer to these text boxes in code. Alternatively, you can use SubformName.Form.Recordset.RecordCount.<hr>
    I tried this and it didn't work. I had to use RecordsetClone instead (i.e. "SubformName.Form.RecordsetClone.RecordCount"). For example:
    <pre> If Me!subfrmTest.Form.RecordsetClone.RecordCount < 1 Then
    'Do something
    End If
    </pre>


Posting Permissions

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