ferociousllama
Registered User.
- Local time
- Yesterday, 16:44
- Joined
- Dec 11, 2015
- Messages
- 10
Hi Everyone.
I have been a lurker on this forum for a very long time and I've gotten much great advice and information. I'm happy there are communities like this one!
I'm not that new to Access but my skill level is certainly novice. I have been using it for a couple years for mostly simple things and am just now getting into using VBA to do some of the more awesome things Access is capable of.
I have code below that emails each email address on a query with an attached file from another field for that same record. It is set to display the email before sending but I will be changing that to send directly once I'm able to get it to do everything I want it to do and test to make sure it's doing everything correctly.
It works great but after the emails are sent to everyone on the list I have to go back and manually change the status field from "Not sent" to "Sent". I like the idea of making the update to the status automatically so I (or whoever is using the database) doesn't forget.
Along the same line, I'd like to enter todays date into another field to indicate when the email was sent.
Is it possible to make these two pieces of information enter as this code is running?
I apologize if this is a super simple problem
Thank you to everyone in advance for your help!
I have been a lurker on this forum for a very long time and I've gotten much great advice and information. I'm happy there are communities like this one!
I'm not that new to Access but my skill level is certainly novice. I have been using it for a couple years for mostly simple things and am just now getting into using VBA to do some of the more awesome things Access is capable of.
I have code below that emails each email address on a query with an attached file from another field for that same record. It is set to display the email before sending but I will be changing that to send directly once I'm able to get it to do everything I want it to do and test to make sure it's doing everything correctly.
Code:
Sub email_exp1_Click()
Dim MyDb As DAO.Database
Dim rsEmail As DAO.Recordset
Dim qdf As DAO.QueryDef
Dim prm As DAO.Parameter
Dim strEmail As String
Dim strMsg As String
Dim oLook As Object
Dim oMail As Object
Set MyDb = CurrentDb
Set qdf = MyDb.QueryDefs("Table1 Query")
For Each prm In qdf.Parameters
prm.Value = Eval(prm.Name)
Next
Set rsEmail = qdf.OpenRecordset()
Set oLook = CreateObject("Outlook.Application")
With rsEmail
.MoveFirst
Do Until rsEmail.EOF
myRecipient = .Fields(1)
invoice = .Fields(0)
If IsNull(myRecipient) = False Then
Set oLook = CreateObject("Outlook.Application")
Set oMail = oLook.CreateItem(0)
With oMail
.To = myRecipient
.Body = "See attached"
.Subject = "Test Email"
.Attachments.Add invoice
.Display
End With
End If
.MoveNext
Loop
End With
Set oMail = Nothing
Set oLook = Nothing
End Sub
Along the same line, I'd like to enter todays date into another field to indicate when the email was sent.
Is it possible to make these two pieces of information enter as this code is running?
I apologize if this is a super simple problem
