Get Data From List Box Selection

G

Guest

I have a form named GroupEmail that allows user to input criterion and then
populate a List Box on the form called ListBoxClients. I want to let the user
further select records from the List Box, and compile a group email. But I
cannot get it to work properly.

Here is code to allow selected records to concatenate the email
addresses...multi-select is enabled,
-----------------------------------------
Private Sub ListBoxClients_Click()
Dim varItem As Variant
Dim strList As String

With Me!ListBoxClients
If .MultiSelect = 0 Then
strList = .Value
Else
For Each varItem In .ItemsSelected
strList = strList & .Column(4, varItem) & ";"
Next varItem
strList = Left$(strList, Len(strList) - 1)

End If
End With

End Sub
---------------
And the code that tries to prepare email message...

Private Sub cmdEmail_Click()
On Error GoTo Err_cmdEmail_Click

Dim strEmail As String
Dim strMailSubject As String
Dim strMsg As String

strEmail = Me.strList & vbNullString
strMailSubject = "Subject"
strMsg = "Message"

DoCmd.SendObject objecttype:=acSendNoObject, _
ObjectName:=acSendNoObject, outputformat:=acFormatHTML, _
To:=strEmail, Subject:=strMailSubject, MessageText:=strMsg

Exit_cmdEmail_Click:
Exit Sub

Err_cmdEmail_Click:
MsgBox Err.Description
Resume Exit_cmdEmail_Click

End Sub
------------------
I can multi-select records in the list box, but when i try to create the
email, I get a Complie Error: method or data member not found with .strList
highlighted in cmdEmail_Click...

I have cobbled this together from various sources, and just do not
understand what's missing...

Txs,
Tom
 
P

pietlinden

I have a form named GroupEmail that allows user to input criterion and then
populate a List Box on the form called ListBoxClients. I want to let the user
further select records from the List Box, and compile a group email. But I
cannot get it to work properly.

Here is code to allow selected records to concatenate the email
addresses...multi-select is enabled,
-----------------------------------------
Private Sub ListBoxClients_Click()
Dim varItem As Variant
Dim strList As String

With Me!ListBoxClients
If .MultiSelect = 0 Then
strList = .Value
Else
For Each varItem In .ItemsSelected
strList = strList & .Column(4, varItem) & ";"
Next varItem
strList = Left$(strList, Len(strList) - 1)

End If
End With

End Sub
---------------
And the code that tries to prepare email message...

Private Sub cmdEmail_Click()
On Error GoTo Err_cmdEmail_Click

Dim strEmail As String
Dim strMailSubject As String
Dim strMsg As String

strEmail = Me.strList & vbNullString
strMailSubject = "Subject"
strMsg = "Message"

DoCmd.SendObject objecttype:=acSendNoObject, _
ObjectName:=acSendNoObject, outputformat:=acFormatHTML, _
To:=strEmail, Subject:=strMailSubject, MessageText:=strMsg

Exit_cmdEmail_Click:
Exit Sub

Err_cmdEmail_Click:
MsgBox Err.Description
Resume Exit_cmdEmail_Click

End Sub
------------------
I can multi-select records in the list box, but when i try to create the
email, I get a Complie Error: method or data member not found with .strList
highlighted in cmdEmail_Click...

I have cobbled this together from various sources, and just do not
understand what's missing...

Txs,
Tom

what's Me.strList? Is strList a control on your form? That part
looks dodgy.
 
G

Guest

strList is a variable I defined in action List Box_Click, that is supposed to
concatenate all the eail addresses fromm the selected rows...but I myself
have no real clue how to do that properly!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top