Setting up Marco/Module to send a Query via Outlook. (1 Viewer)

Universal_

New member
Local time
Today, 15:50
Joined
Aug 10, 2023
Messages
7
Hello all, hope this finds you all well.

I have a data set produced by queries on access. However I want to set up a macro/module so that I can email the results to specific people in that field. For example the query will generate a number of titles for books and their authors.

I want to send a generic email to all the authors that are populated in the query but have their own title to be the heading of the email.

Is this possible?

Thanks for dealing with my message and looking forward to learning about this
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:50
Joined
Oct 29, 2018
Messages
21,473
Yes, that's possible, but it would involve a loop.

How familiar are you with VBA?
 

Universal_

New member
Local time
Today, 15:50
Joined
Aug 10, 2023
Messages
7
sadly not however willing to learn!
 

Universal_

New member
Local time
Today, 15:50
Joined
Aug 10, 2023
Messages
7
Sorry for the delayed response, got side tracked a little but have finally got a code working. Just wanted to check one last thing.

Is there a way to add my outlook signature automatically at the end of the email, and is there a way to add whatever user runs the macro their outlook signature onto the email?

The code ive got so far is:

Option Compare Database

Sub SendEmails()
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim rs As DAO.Recordset
Dim outlookApp As Object
Dim outlookMail As Object
Dim strSQL As String

Const queryName As String = "Book Titles"

Set db = CurrentDb
Set qdf = db.QueryDefs(queryName)
Set rs = qdf.OpenRecordset()

Set outlookApp = CreateObject("Outlook.Application")

Do Until rs.EOF
Dim leadName As String
Dim leadEmail As String
Dim leadTitle As String

Name = rs("Authors") '
Email = rs("Emails") '
Title = rs("Title") '

Set outlookMail = outlookApp.CreateItem(0)
With outlookMail
.To = Email
.Subject = "Book Title Reminder"
.Body = " email body" vbCrLf & "Kind Regards"

.Display '
End With

rs.MoveNext
Loop

rs.Close
Set rs = Nothing
Set qdf = Nothing
Set db = Nothing
Set outlookApp = Nothing
Set outlookMail = Nothing
End Sub
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:50
Joined
Oct 29, 2018
Messages
21,473
Is there a way to add my outlook signature automatically at the end of the email, and is there a way to add whatever user runs the macro their outlook signature onto the email?
Should be possible. There are a couple of approaches on that. Will Outlook be open already when the user runs this code?
 

Universal_

New member
Local time
Today, 15:50
Joined
Aug 10, 2023
Messages
7
Should be possible. There are a couple of approaches on that. Will Outlook be open already when the user runs this code?
outlook will already be open whenever the code is run on all users
 

Users who are viewing this thread

Top Bottom