Hello all .... I hope you are well.
I'm new to VBA and needed some assistance. :banghead:
I have created something from our transport department and need to set up so he can select a command button and email from a query, but where would I put the query details in the coding below
VBA used
Dim strSQL
Dim db As DAO.Database
Dim MailList As DAO.Recordset
Dim objOutlook As Outlook.Application
Dim objemail As Outlook.MailItem
Dim Subjectline As String
Dim BodyFile As String
Dim fso As FileSystemObject
Dim MyBody As TextStream
Dim MyBodyText As String
Dim MyDecision As String
Dim strReportName As String
Dim strEnroll As String
Dim strWho As String
Dim strEmail As String
Set fso = New FileSystemObject
Set objOutlook = New Outlook.Application
Set db = CurrentDb()
Set MailList = db.OpenRecordset("qryEmail")
Subjectline$ = "Transport Request" & " " & Date
Set objemail = objOutlook.CreateItem(olMailItem)
Do While Not MailList.EOF
MyBodyText = MailList("qryemail") & " - " & MailList("ExpirationDate")
MailList.MoveNext
Loop
MyMail.To = "" & ""
MyMail.CC = CurrentUser() & ""
MyMail.Subject = Subjectline$
MyMail.Body = MyBodyText
MyMail.Display
strEmail = Now()
strWho = CurrentUser()
Set MyMail = Nothing
Set MyOutlook = Nothing
using the query (qryemail)
colID
coldate
companyname
address
address1
county
town
postcode
any help on what to do would be a massive help, if you need any further information feel free to ask
Thanks
Emma
I'm new to VBA and needed some assistance. :banghead:
I have created something from our transport department and need to set up so he can select a command button and email from a query, but where would I put the query details in the coding below

VBA used
Dim strSQL
Dim db As DAO.Database
Dim MailList As DAO.Recordset
Dim objOutlook As Outlook.Application
Dim objemail As Outlook.MailItem
Dim Subjectline As String
Dim BodyFile As String
Dim fso As FileSystemObject
Dim MyBody As TextStream
Dim MyBodyText As String
Dim MyDecision As String
Dim strReportName As String
Dim strEnroll As String
Dim strWho As String
Dim strEmail As String
Set fso = New FileSystemObject
Set objOutlook = New Outlook.Application
Set db = CurrentDb()
Set MailList = db.OpenRecordset("qryEmail")
Subjectline$ = "Transport Request" & " " & Date
Set objemail = objOutlook.CreateItem(olMailItem)
Do While Not MailList.EOF
MyBodyText = MailList("qryemail") & " - " & MailList("ExpirationDate")
MailList.MoveNext
Loop
MyMail.To = "" & ""
MyMail.CC = CurrentUser() & ""
MyMail.Subject = Subjectline$
MyMail.Body = MyBodyText
MyMail.Display
strEmail = Now()
strWho = CurrentUser()
Set MyMail = Nothing
Set MyOutlook = Nothing
using the query (qryemail)
colID
coldate
companyname
address
address1
county
town
postcode
any help on what to do would be a massive help, if you need any further information feel free to ask
Thanks
Emma
Last edited: