Expanding/Collapsing Subdatasheet

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dima69
    Recognized Expert New Member
    • Sep 2006
    • 181

    Expanding/Collapsing Subdatasheet

    Hi everybody. Here is another problem I cannot find the solution.
    I have a form with subform. In datasheet view, the subform related to current record can be expanded as subdatasheet by clicking on the "+" sign.
    So the question is how to expand SINGLE subform from VB code.
    Note that SubdatasheetExp anded form property doesn't help here, since it affects ALL the subforms in current datasheet view.
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by dima69
    Hi everybody. Here is another problem I cannot find the solution.
    I have a form with subform. In datasheet view, the subform related to current record can be expanded as subdatasheet by clicking on the "+" sign.
    So the question is how to expand SINGLE subform from VB code.
    Note that SubdatasheetExp anded form property doesn't help here, since it affects ALL the subforms in current datasheet view.
    This code will work for a specific SubForm:
    [CODE=vb]'Set the Focus on your SubForm Control
    Me![<your subform control name>].SetFocus

    'Select ALL Records in the SubForm
    DoCmd.RunComman d acCmdSelectAllR ecords

    'Hold SHIFT and CTRL, then press the DOWN Arrow to Expand all SubDatasheets
    SendKeys "+^({DOWN}) "

    'Hold SHIFT and CTRL, then press the UP Arrow to Collapse all SubDatasheets
    SendKeys "+^({UP})"[/CODE]
    NOTE: There is probably a better solution, this was off the top of my head.

    Comment

    • dima69
      Recognized Expert New Member
      • Sep 2006
      • 181

      #3
      Originally posted by ADezii
      This code will work for a specific SubForm:
      [CODE=vb]'Set the Focus on your SubForm Control
      Me![<your subform control name>].SetFocus

      'Select ALL Records in the SubForm
      DoCmd.RunComman d acCmdSelectAllR ecords

      'Hold SHIFT and CTRL, then press the DOWN Arrow to Expand all SubDatasheets
      SendKeys "+^({DOWN}) "

      'Hold SHIFT and CTRL, then press the UP Arrow to Collapse all SubDatasheets
      SendKeys "+^({UP})"[/CODE]
      NOTE: There is probably a better solution, this was off the top of my head.
      Thanks, it may give half of the solution, since it works only for expansion, and not for the collapsion.

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        Originally posted by dima69
        Thanks, it may give half of the solution, since it works only for expansion, and not for the collapsion.
        I had it working both ways on my PC, cannot understand the difference.

        Comment

        • dima69
          Recognized Expert New Member
          • Sep 2006
          • 181

          #5
          Originally posted by ADezii
          I had it working both ways on my PC, cannot understand the difference.
          How can you put the focus on the subform while it is not expanded ?
          btw, I am working on Access2002.

          Comment

          • dima69
            Recognized Expert New Member
            • Sep 2006
            • 181

            #6
            Sorry, my mistake. It really works both ways ! Thanks a lot !

            Comment

            • Denburt
              Recognized Expert Top Contributor
              • Mar 2007
              • 1356

              #7
              I so hate the sendkeys statement and avoid them when I can (sometimes you can't) here is another solution.

              You can find the following example in the help file highlight "SubdatasheetEx panded" then click F1 and you can get more info such as height etc.
              [CODE=VB]Dim strExpand As String

              With Forms("Purchase Orders")

              strExpand = InputBox("Expan d subdatasheets? Y/N")

              Select Case strExpand
              Case "Y"
              .SubdatasheetEx panded = True
              Case "N"
              .SubdatasheetEx panded = False
              Case Else
              MsgBox "Can't determine subdatasheet expansion state."
              End Select

              End With[/CODE]

              Comment

              • dima69
                Recognized Expert New Member
                • Sep 2006
                • 181

                #8
                Originally posted by Denburt
                I so hate the sendkeys statement and avoid them when I can (sometimes you can't) here is another solution.

                You can find the following example in the help file highlight "SubdatasheetEx panded" then click F1 and you can get more info such as height etc.
                [CODE=VB]Dim strExpand As String

                With Forms("Purchase Orders")

                strExpand = InputBox("Expan d subdatasheets? Y/N")

                Select Case strExpand
                Case "Y"
                .SubdatasheetEx panded = True
                Case "N"
                .SubdatasheetEx panded = False
                Case Else
                MsgBox "Can't determine subdatasheet expansion state."
                End Select

                End With[/CODE]
                I hate SendKeys too, but I cannot use SubdatasheetExp anded property either, because it affects all records in main datasheet - I've explaned this in post #1.

                Comment

                • Denburt
                  Recognized Expert Top Contributor
                  • Mar 2007
                  • 1356

                  #9
                  Sorry missed that in your first post I did a little digging and it is perplexing. I would think there must be a way but as of yet had no success. Good Luck and I will keep looking.

                  Comment

                  Working...