Another Multiselect Question

jsimo01

New member
Local time
Today, 01:41
Joined
Sep 3, 2007
Messages
7
In brief: I would like to use a multi-select listbox on a pop-up form to set values on a text box control on my main form.

As I have more than one multi-select list box the main is becoming a little bit busy with all the additional list boxes and command buttons that are needed for the only working example I have managed to cobble together from samples posted here and elsewhere.

If possible, I would like to be able to select one item from the pop-up which would then be updated on the main form, followed by the selection of another item from the pop-up which would then be added (concatenated?) to the first entry, seperated by a semicolon or something! and so on and so forth.

I have seen this done elsewhere with a cleverly disguised command button on the main form which gives the illusion of a drop-down menu or combo box.

I am quite new VBA so apologise if I have not quite grasped the full extent of what i would propose to do.

Sorry if this has already been asked and answered, I couldn't quite find a clear solution.

My Sincere Thanks in anticipation of any response!

John
 
You can loop through a multiselect box:
Code:
for intX = 0 to Me.lstForms.ItemsSelected.Count -1
   ...
   strAap = strAap & Me.lstForms.ItemData(intX)
   ...
next intX
 
Thanks,

The code I have is

Code:
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![Find Type].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![Find Type List].ItemData(iListItemsCount)), Trim(sValue)) = 0 Then
                    Me![Find Type List].Selected(iListItemsCount) = True
                    bFound = True
                End If
                iListItemsCount = iListItemsCount + 1
            Loop Until bFound = True Or iListItemsCount = Me![Find Type List].ListCount
            sValue = ""
        Else
            sValue = sValue & sChar
        End If
    Next iCount
End Sub
    
Private Sub clearListBox()
    Dim iCount As Integer
        
    For iCount = 0 To Me![Find Type List].ListCount
        Me![Find Type List].Selected(iCount) = False
    Next iCount
End Sub



Private Sub multiselect_Click()
    Dim oItem As Variant
    Dim sTemp As String
    Dim iCount As Integer
    
    iCount = 0
            
    If Me![Find Type List].ItemsSelected.Count <> 0 Then
        For Each oItem In Me![Find Type List].ItemsSelected
            If iCount = 0 Then
                sTemp = sTemp & Me![Find Type List].ItemData(oItem)
                iCount = iCount + 1
            Else
                sTemp = sTemp & "," & Me![Find Type List].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![Find Type].Value = sTemp
End Sub

I would like to open the ListBox [Find Type List] as a pop-up form to select the values from and then transfer them to a TextBox [Find Type] on the main form. I have tried several attempts to modify the code but I am a little out of my depth here! I ideally would also like to do this without having to use a command button to transfer the values across.

I Thank you for any comments or suggestions you may have.
 
Clearly you have to use an event to get things in motion.
How would the program know you have finished typing? Use Lostfocus on Keypress to get the value across
 
Progress made - Thanks!

Hi, Thanks again,

I have attached a first draft, if you have the opportunity to review and comment it would be extremely helpful. (I apologise it is a little crude).

I am having an error message appear 'Overflow Error No.6' or something which I haven't yet solved. I am still trying to work out how to automate the closing of the pop-up after the user makes their selection and neaten up the command button, but it is at least a step in the right direcction.
 

Attachments

I changed a few things;
Table HER: Record No Number:Long -> RecordNo Autonumber:Long
The form with the listbox, shows the selected items in the list.
Added a few functions in modUtil.

Note: Your comma separator conflicts with your thousand separator!

Dont use spaces in your fieldnames or anywhere else, except for captions ofcourse.

Enjoy!
 

Attachments

Last edited:

Users who are viewing this thread

Back
Top Bottom