Hello...
So recently I set up a combo box that could email out items to a group. The client wants it changed so that she can select multiple groups and email them at the same time. Is there an easy way of going from a combo box to a list box without having to change too much of the code. The code that I used with the combo box is below:
Code:
Private Sub btnSend_Click()
Dim OlApp As Object
Dim OlMail As Object
Dim rs As DAO.Recordset
Dim ToRecipient As String
Set OlApp = CreateObject("Outlook.Application")
Set OlMail = OlApp.CreateItem(olMailItem)
If Me.lstGroup.Column(1) = "Group A" Then
Set rs = CurrentDb.OpenRecordset("SELECT Email FROM qryA")
Do While rs.EOF = False
OlMail.Recipients.Add rs!Email
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Else
If Me.lstGroup.Column(1) = "Group B" Then
Set rs = CurrentDb.OpenRecordset("SELECT Email FROM qryB")
Do While rs.EOF = False
OlMail.Recipients.Add rs!Email
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Else
If Me.lstGroup.Column(1) = "Group C" Then
Set rs = CurrentDb.OpenRecordset("SELECT Email FROM qryC")
Do While rs.EOF = False
OlMail.Recipients.Add rs!Email
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Else
If Me.lstGroup.Column(1) = "Group D" Then
Set rs = CurrentDb.OpenRecordset("SELECT Email FROM qryD")
Do While rs.EOF = False
OlMail.Recipients.Add rs!Email
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Else
If Me.lstGroup.Column(1) = "Group E" Then
Set rs = CurrentDb.OpenRecordset("SELECT Email FROM qryE")
Do While rs.EOF = False
OlMail.Recipients.Add rs!Email
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Else
If Me.lstGroup.Column(1) = "Group F" Then
Set rs = CurrentDb.OpenRecordset("SELECT Email FROM qryF")
Do While rs.EOF = False
OlMail.Recipients.Add rs!Email
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Else
If Me.lstGroup.Column(1) = "Group G" Then
Set rs = CurrentDb.OpenRecordset("SELECT Email FROM qryG")
Do While rs.EOF = False
OlMail.Recipients.Add rs!Email
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
End If
End If
End If
End If
End If
End If
End If
OlMail.Subject = " "
OlMail.Display
End Sub