Multiple Select in Access 2003

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • g diddy
    New Member
    • Sep 2009
    • 54

    Multiple Select in Access 2003

    Hi

    I'm using a statement to call other Subs if a unit (or multiple units) in a multi-select list box has been selected (and if not - do nothing). I know that the part below in Bold and Underlined is wrong but I cannot think of what it should be. I've tried a few variations of that part but still it doesn't work. By any chance can you help me with this? Basically i want this for loop to go through the list box (cmbUnit) and for every item selected call one of the two functions in the inner IF statement.

    Code:
            ElseIf optWho.Value = 2 Then    
                For j = 0 To (cmbUnit.ListCount - 1)
                    [B][U]If cmbUnit.Value = True Then [/U][/B]
                    [B][U]cmbUnit.ListIndex = j [/U][/B]
                       If optFormat.Value = 1 Then
                           Call SaveUnitNEWxls(MYnewFolder)
                       ElseIf optFormat.Value = 2 Then
                           Call SaveUnitNEW(MYnewFolder)
                       End If
                    End If
                    ProgBarGo.Value = ProgBarGo.Value + 1
                Next j
            End If
    Your help is greatly appreciated. Thanks for your time
  • topher23
    Recognized Expert New Member
    • Oct 2008
    • 234

    #2
    The problem, I think, is that you're using a multi-select box, but ListIndex sets a single selection, and then you lose your original multiple selections. Try this code out:

    Code:
            ElseIf optWho.value = 2 Then
                For J = 0 To (cmbUnit.ListCount - 1)
                    If cmbUnit.Selected(J) = True Then
                       If optFormat.value = 1 Then
                           Call SaveUnitNEWxls(MYnewFolder)
                       ElseIf optFormat.value = 2 Then
                           Call SaveUnitNEW(MYnewFolder)
                       End If
                    End If
                    ProgBarGo.value = ProgBarGo.value + 1
                Next J
            End If
    If the subroutines you are using need to reference the list box field's value, set them to accept the J value as an argument and then reference cmbUnit.ListInd ex(J) instead.

    Comment

    • g diddy
      New Member
      • Sep 2009
      • 54

      #3
      Thank you very much for your quick response! i'll give it a try now!

      Comment

      Working...