Insert Value Not presented in the multi select list box choices access 2007 (1 Viewer)

ramindya

New member
Local time
Today, 08:00
Joined
Feb 22, 2012
Messages
9
I have created a multi selected list box functionality like in the attachment which has a unbound control with possible choice of list items and also a text box were the selected choices can be inserted into the text box.

What it does? I am able to select one or all the choices that is present in the selection and click Insert and the choices are inserted into the text box.
I used the following code provided by support.microsoft.com/kb/827423 and it works perfectly.

What it does not do? I want to also insert any free text in the text box
(other than the choices present in the unbound list box control).

The sample code in the above link:

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

Please let me know how to do it. I am very new to VBA and programming.

Thanks for your help!

Thanks,
Rom
 

Attachments

  • sample.png
    sample.png
    3.9 KB · Views: 106

AccessMSSQL

Seasoned Programmer-ette
Local time
Today, 08:00
Joined
May 3, 2012
Messages
636
You are typing free text in another textbox? Then you would do something like this:

Dim sAllText as String
Dim sFreeText as string
sFreeText = me.txtMyFreeText
sAllText = me.Myselections.value & "," & sFreeText
me!MySelections.Value = sAllText
 

Users who are viewing this thread

Top Bottom