I am very new to using VBA, so hopefully someone can help me. I am trying to email certain groups by using a Combo Box. If I select a group in the list and then send email, it opens Outlook fine, but with no addresses in the To: field. This is with using If...Else statements or Select Case statements. But if I get rid of the conditional statements, it works fine and pulls the right addresses. Can someone tell me how I can get it to open Outlook with the emails populated in the To: Field?
Here is what I have in my code:
Code:
Public 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.GroupLst = "Group A" Then
Set rs = CurrentDb.OpenRecordset("SELECT Email FROM qryGrpA")
Do While rs.EOF = False
ToRecipient = rs!Email
OlMail.Recipients.Add ToRecipient
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Else
If Me.GroupLst = "Group B" Then
Set rs = CurrentDb.OpenRecordset("SELECT Email FROM qryGrpB")
Do While rs.EOF = False
ToRecipient = rs!Email
OlMail.Recipients.Add ToRecipient
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
End If
End If
OlMail.Subject = " "
OlMail.Display
End Sub