Connecting Tech Pros Worldwide Forums | Help | Site Map

Multiple Select in Access 2003

Member
 
Join Date: Sep 2009
Posts: 39
#1: 3 Weeks Ago
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.

Expand|Select|Wrap|Line Numbers
  1.         ElseIf optWho.Value = 2 Then    
  2.             For j = 0 To (cmbUnit.ListCount - 1)
  3.                 If cmbUnit.Value = True Then 
  4.                 cmbUnit.ListIndex = j 
  5.                    If optFormat.Value = 1 Then
  6.                        Call SaveUnitNEWxls(MYnewFolder)
  7.                    ElseIf optFormat.Value = 2 Then
  8.                        Call SaveUnitNEW(MYnewFolder)
  9.                    End If
  10.                 End If
  11.                 ProgBarGo.Value = ProgBarGo.Value + 1
  12.             Next j
  13.         End If
  14.  
Your help is greatly appreciated. Thanks for your time

Expert
 
Join Date: Oct 2008
Location: Cedar City, Utah, USA
Posts: 100
#2: 3 Weeks Ago

re: Multiple Select in Access 2003


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:

Expand|Select|Wrap|Line Numbers
  1.         ElseIf optWho.value = 2 Then
  2.             For J = 0 To (cmbUnit.ListCount - 1)
  3.                 If cmbUnit.Selected(J) = True Then
  4.                    If optFormat.value = 1 Then
  5.                        Call SaveUnitNEWxls(MYnewFolder)
  6.                    ElseIf optFormat.value = 2 Then
  7.                        Call SaveUnitNEW(MYnewFolder)
  8.                    End If
  9.                 End If
  10.                 ProgBarGo.value = ProgBarGo.value + 1
  11.             Next J
  12.         End If
  13.  
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.ListIndex(J) instead.
Member
 
Join Date: Sep 2009
Posts: 39
#3: 3 Weeks Ago

re: Multiple Select in Access 2003


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