mistyinca1970
Member
- Local time
- Today, 15:24
- Joined
- Mar 17, 2021
- Messages
- 117
Good morning,
Let me preface this with I do not really know vb coding. I basically find bits and pieces here and there to try and make it work for me. I am stumped on a send email code. I have built a contacts database. This will house name, org, and contact information such as email and phone numbers. One of the key features of this database is the ability to send email to contacts based on lists created for various committees. So these lists are obviously queries. I have several queries containing lists of email addresses. The queries will be listed in a List Box in a form. The user will select a query from the list box, and click a button to send email to everyone in the query.
I am using the function QueryFieldAsSeparatedString to delimit the list of names in the Email field. That part of this works fine. What is NOT happening is being able to get the delimited list of emails into an outlook email. When I click the button, nothing happens.
Here is my code (lstQueryList is the listbox containing all the queries. See below for a pic of the form):
Let me preface this with I do not really know vb coding. I basically find bits and pieces here and there to try and make it work for me. I am stumped on a send email code. I have built a contacts database. This will house name, org, and contact information such as email and phone numbers. One of the key features of this database is the ability to send email to contacts based on lists created for various committees. So these lists are obviously queries. I have several queries containing lists of email addresses. The queries will be listed in a List Box in a form. The user will select a query from the list box, and click a button to send email to everyone in the query.
I am using the function QueryFieldAsSeparatedString to delimit the list of names in the Email field. That part of this works fine. What is NOT happening is being able to get the delimited list of emails into an outlook email. When I click the button, nothing happens.
Here is my code (lstQueryList is the listbox containing all the queries. See below for a pic of the form):
Code:
Private Sub btnSendEmail_Click()
Dim db As DAO.Database
Dim rs As DAO.Database
Dim emailTo As String
Dim retVal As String
Dim outApp As Outlook.Application
Dim outMail As Outlook.MailItem
Dim outlookStarted As Boolean
On Error Resume Next
Set outApp = GetObject(, "Outlook.Application")
On Error GoTo 0
If outApp Is Nothing Then
Set outApp = CreateObject("Outlook.Application")
outlookStarted = True
End If
emailTo = QueryFieldAsSeparatedString("EmailAddress", lstQueryList.Value, , , ",")
End Sub