I have been working in copy and paste for years and would love to automate the bi-monthly invoice summary e-mails that I send to my customers!
My Access 2013 database creates summaries for customers exported to an excel spreadsheet.
With the help of Ron De Bruin code, I was able to have excel split the worksheet into separate workbooks.
Back in Access, I have a parameter query that will pull a list of these customers and the path and file to their summary, like this
STID CustID ACCT APCEmail STMTAP STDATE STMTPATH
30 740 999999 hmc@123.com TRUE 05-Jan-19 C:\User\Summaries\EMAIL\999999.xlsx
I'm not sure where to begin!!
Do I start with DAO to set database and recordset, then loop through with MoveFirst & DoUntil, build the e-mail name, subject and message with string and SendObject?
2 4596
I do something similar to what it is you're trying to do. Here is the code I use. Hopefully you can adapt it to your needs. -
-
Private Sub SendEmailPass()
-
-
Dim db As DAO.Database
-
Dim rs As DAO.Recordset
-
Dim rs1 As DAO.Recordset
-
Dim qdf As DAO.QueryDef
-
Dim strTo As String
-
Dim strCC As String
-
Dim strSubject As String
-
Dim strBody As String
-
Dim strMaintActy As String
-
Dim strShopCode As String
-
Dim strShipName As String
-
Dim intPassCode As Integer
-
Dim strPassCode As String
-
Dim intWC As Integer
-
Dim outApp As Outlook.Application
-
Dim outMail As Outlook.MailItem
-
Dim intPE As Integer
-
Dim intCSPE As Integer
-
-
On Error Resume Next
-
Set outApp = GetObject(, "Outlook.Application")
-
On Error GoTo 0
-
-
If outApp Is Nothing Then
-
Set outApp = CreateObject("Outlook.Application")
-
End If
-
-
intWC = Forms![frmJobPasses]![frmAssignments].Form![AssignActy]
-
intPassCode = Nz(Me![frmAssignments].Form![AssignPassCode], 0)
-
intPE = Nz(Forms![frmJobPasses]![sfrmUnitInfo].Form![cboPE], 0)
-
intCSPE = Nz(Forms![frmJobPasses]![sfrmUnitInfo].Form![cboCSPE], 0)
-
strPassCode = Nz(DLookup("PassDescrip", "tblPassCodes", "PassCodeID = " & intPassCode))
-
strShopCode = Nz(DLookup("ShopCode", "tblMaintActyUnits", "UnitID = " & intWC))
-
strMaintActy = Nz(DLookup("Activity", "tblMaintActyUnits", "UnitID = " & intWC))
-
strShipName = Nz(DLookup("ShipFullName", "qryShipName", "UnitID = " & Me.UnitID))
-
-
Set db = CurrentDb
-
Set qdf = db.QueryDefs("qrySelectEmail")
-
Set rs1 = db.OpenRecordset("qrySelectCC")
-
-
strTo = vbNullString
-
With qdf
-
.Parameters("intUnitID") = intWC
-
Set rs = .OpenRecordset
-
rs.MoveFirst
-
Do Until rs.EOF
-
strTo = strTo & rs.Fields(0) & ";" & vbCrLf
-
rs.MoveNext
-
Loop
-
End With
-
strTo = strTo & GetPE(intPE, intCSPE)
-
-
With rs1
-
strCC = vbNullString
-
rs1.MoveFirst
-
Do Until rs1.EOF
-
strCC = strCC & .Fields(0) & ";" & vbCrLf
-
rs1.MoveNext
-
Loop
-
strCC = strCC & ";" & Me.UnitPOC_Email
-
End With
-
-
-
strSubject = "** EMAIL PASS ** FROM FDRMC TO " & strMaintActy & " - " & strShopCode _
-
& " FOR " & strShipName & " / " & Me.JobEquip & " / " & Replace(Me.JobCat, "C", "CAT") _
-
& " / CASREP: " & Me.JobNum & " / DTG: " & Me.JobDTG
-
-
strBody = strMaintActy & ": Please reply to all and confirm acceptance of support and assigned technician," _
-
& " and include the FDRMC Naples CDO <mailto:YourEmail@YourDomain.com > on all related email traffic." & vbCrLf _
-
& vbCrLf _
-
& "1. Equipment: " & Me.JobEquip & vbCrLf _
-
& "2. For detailed information see DTG: " & Me.JobDTG & vbCrLf _
-
& "3. Job Number: " & Me.JCN & vbCrLf _
-
& "4. Requested Action: " & Me.JobAction & vbCrLf _
-
& "5. Reason for pass: " & strPassCode & vbCrLf _
-
& "6. Ship's POC information: " & Me.UnitPOC & " / " & Me.UnitPOC_Email & vbCrLf _
-
& "7. Request CC <YourEmail@YourDomain.com> on all correspondence for tracking purposes."
-
strBody = strBody & vbCrLf _
-
& vbCrLf _
-
& "Very Respectfully,"
-
-
-
Set outMail = outApp.CreateItem(olMailItem)
-
With outMail
-
.To = strTo
-
.CC = strCC
-
.Subject = strSubject
-
.Body = strBody
-
.Display
-
-
End With
-
-
exit_handler:
-
rs.Close
-
rs1.Close
-
Set rs = Nothing
-
Set db = Nothing
-
Set rs = Nothing
-
Set outMail = Nothing
-
Set outApp = Nothing
-
-
End Sub
-
If you are using Outlook, as very helpful article is here.
Yes, the basics are this: - Option Compare Database
-
Option Explicit
-
-
Private Sub SendEmail_Click()
-
On Error GoTo EH
-
Dim db As DAO.Database
-
Dim rst As DAO.Recordset
-
Dim strSendTo As String
-
Dim strSubject As String
-
Dim strEMailBody As String
-
Dim strCCLine As String
-
Dim strBCCLine As String
-
Dim strOnBehalfOf As String
-
Dim strAtchs As String
-
-
Set db = CurrentDb()
-
Set rst = db.OpenRecordset("YourQuery")
-
With rst
-
If Not (.BOF And .EOF) Then
-
Call .MoveFirst
-
Do While Not .EOF
-
strSendTo = !EmailAddress
-
'...
-
'build the rest of your e-mail
-
'...
-
-
'Generate and Display the E-Mail
-
Call SendAnEMail(olSendTo:=strSendTo, _
-
olSubject:=strSubject, _
-
olEMailBody:=strEMailBody, _
-
olDisplay:=True, _
-
olCCLine:=strCCLine, _
-
olBCCLine:=strBCCLine, _
-
olOnBehalfOf:=strOnBehalfOf, _
-
olAtchs:=strAtchs, _
-
SendAsHTML:=False)
-
-
Call .MoveNext
-
Loop
-
End If
-
Call .Close
-
End With
-
db.Close
-
Set rst = Nothing
-
Set db = Nothing
-
-
EH:
-
Set rst = Nothing
-
Set db = Nothing
-
Call MsgBox(Prompt:="There was an Error", _
-
Buttons:=vbOKOnly, _
-
Title:="Call teh DBA!")
-
End Sub
Hope this hepps!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: dave |
last post by:
hi guys
I m trying to execute few lines code tht i have copies
from microsoft tech script centre.
basically its to send email without using any smtp
service. u can find the code snippet from...
|
by: Just D. |
last post by:
All,
What is the simplest way to send an email message through the MS SQL Server?
There was a method to send email messages using a standard C# way via SMTP
server, but the required port was...
|
by: ErwinF |
last post by:
Hi there,
I would like to know the following:
How to send send email attachments using WebDAV in VB .NET? Sample code please...................
Thanks for your help.
|
by: Atenza |
last post by:
Hi all,
I develop an VB6 program to send email by using CDOSYS.DLL. It works fine as
follow:
Dim iMsg As New CDO.Message
Dim iDsrc As CDO.IDataSource
Set iDsrc = iMsg ' (QueryInterface)...
|
by: tulasikumar |
last post by:
hi all,
i have faced with one problem regarding multiple attachments sending through
System.Net.Mail in Asp.net2.0.Any one Please tell me the solution for
this.Any one have solution for this...
|
by: Atran |
last post by:
Hello Everybody, I want to send a message to somebody email using C# I have the right code but when I run the application it shown the "ArgumentExecption was unhandled" error, it is been yellow, it...
|
by: phill86 |
last post by:
Hi
I am using the following code to send an email from access via outlook automatically
DoCmd.SendObject acSendReport, stDocName, acFormatRTF, "User", , , , , False
|
by: mulamootil |
last post by:
Hi - Is it possible to send email attachments to an Access Database. I know that we can collect data using email messages. It would be nice if there was a way to send an email with an attachment and...
|
by: Jeffrey Tan |
last post by:
Hi. I was wondering if there was a way to send an email without using the Send Object method for a macro. if you use the macro, you will get this warning:...
|
by: vffg5555555555 |
last post by:
how to send email attachments with encryption
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |