A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

multiple selection list box



 
 
Thread Tools Display Modes
  #1  
Old January 9th, 2010, 08:12 PM posted to microsoft.public.access.forms
stan
external usenet poster
 
Posts: 198
Default multiple selection list box

The following code will allow multiple selections from a list box to be fed
into a list box. My question is how would I modity this code so that I could
use it with multiple list boxes on the same form. It works for only one box.
Can, for example, multiple instances of the code with object names changed,
be attached to each list box instead of the form?
Option Compare Database
Option Explicit

Private Sub Form_Current()
Dim oItem As Variant
Dim bFound As Boolean
Dim sTemp As String
Dim sValue As String
Dim sChar As String
Dim iCount As Integer
Dim iListItemsCount As Integer

sTemp = Nz(Me!mySelections.Value, " ")
iListItemsCount = 0
bFound = False
iCount = 0

Call clearListBox

For iCount = 1 To Len(sTemp) + 1
sChar = Mid(sTemp, iCount, 1)
If StrComp(sChar, ",") = 0 Or iCount = Len(sTemp) + 1 Then
bFound = False
Do
If StrComp(Trim(Me!NamesList.ItemData(iListItemsCount )),
Trim(sValue)) = 0 Then
Me!NamesList.Selected(iListItemsCount) = True
bFound = True
End If
iListItemsCount = iListItemsCount + 1
Loop Until bFound = True Or iListItemsCount =
Me!NamesList.ListCount
sValue = ""
Else
sValue = sValue & sChar
End If
Next iCount
End Sub

Private Sub clearListBox()
Dim iCount As Integer

For iCount = 0 To Me!NamesList.ListCount
Me!NamesList.Selected(iCount) = False
Next iCount
End Sub

Private Sub testmultiselect_Click()
Dim oItem As Variant
Dim sTemp As String
Dim iCount As Integer

iCount = 0

If Me!NamesList.ItemsSelected.Count 0 Then
For Each oItem In Me!NamesList.ItemsSelected
If iCount = 0 Then
sTemp = sTemp & Me!NamesList.ItemData(oItem)
iCount = iCount + 1
Else
sTemp = sTemp & "," & Me!NamesList.ItemData(oItem)
iCount = iCount + 1
End If
Next oItem
Else
MsgBox "Nothing was selected from the list", vbInformation
Exit Sub 'Nothing was selected
End If

Me!mySelections.Value = sTemp
End Sub

Private Sub clrList_Click()
Call clearListBox
Me!mySelections.Value = Null
End Sub



--
stan
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 12:03 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.