I need some help with this code please!

LHolden

Registered User.
Local time
Today, 08:21
Joined
Jul 18, 2012
Messages
73
I am not good at VBA at all. I have dabbled a little bit building this database, but I still can't even really read it, I just know what certain strings mean. I'm trying to get a list box populated with names and e-mails to return the e-mails in a list, and separated by semicolons. Microsoft's support pages got me some code to use, but when I hit the command button, it returns the ID field for the names, and I have no idea how to change it.

Code:
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

That is the code that I'm using, and if anyone could help me it would be greatly appreciated.
 
Your list box BOUND field is set to the field where the ID is. Change the Bound property from the current value (likely a 1) to the column number where the email address is in the list box's row source.
 
Thank you so much Bob!

The more you know.
 

Users who are viewing this thread

Back
Top Bottom