This is my first post and I have a limited amount of knowledge of VBA so please bear with me, lol. I am needing to create a script that will allow me to pull from two tables and send 1 message that includes the results in two separate grids. I have the code that will allow for one table, but I don't know how to get it done for the second. Below is the working code. -
Dim olApp As Object
-
Dim olItem As Variant
-
Dim db As DAO.Database
-
Dim rec As DAO.Recordset
-
Dim strQry As String
-
Dim aHead(1 To 2) As String
-
Dim aRow(1 To 2) As String
-
Dim aBody() As String
-
Dim lCnt As Long
-
-
'Create the header row
-
aHead(1) = "Driver Name"
-
aHead(2) = "Expiration Date"
-
-
-
lCnt = 1
-
ReDim aBody(1 To lCnt)
-
aBody(lCnt) = "<HTML><body><table border='2'><tr><th>" & Join(aHead, "</th><th>") & "</th></tr>"
-
-
'Create each body row
-
strQry = "SELECT * From Email_Query"
-
Set db = CurrentDb
-
Set rec = CurrentDb.OpenRecordset("CDL60DayExp")
-
-
-
If Not (rec.BOF And rec.EOF) Then
-
Do While Not rec.EOF
-
lCnt = lCnt + 1
-
ReDim Preserve aBody(1 To lCnt)
-
aRow(1) = rec("Name")
-
aRow(2) = rec("CdlExp")
-
aBody(lCnt) = "<tr><td>" & Join(aRow, "</td><td>") & "</td></tr>"
-
rec.MoveNext
-
Loop
-
End If
-
-
aBody(lCnt) = "Hello," & "<br>" & _
-
"<br>" & _
-
"Below are the drivers with upcoming expirations" & "<br>" & _
-
"<br>" & _
-
aBody(lCnt) & "</table></body></html>"
-
-
-
'create the email
-
Set olApp = CreateObject("Outlook.application")
-
Set olItem = olApp.CreateItem(0)
-
-
olItem.display
-
olItem.To = "someperson@somecompany.net"
-
olItem.Subject = "Upcoming Expirations"
-
olItem.HTMLBody = Join(aBody, vbNewLine)
-
olItem.display
-
1 1339
I see absolutely no easy way to accomplish this, but here goes my attempt. The idea is to: - Create the Code that opens an Instance of Outlook.
- Dynamically create the HTML Table Code based on the first of two Recordsets and assign it to a String Variable. Assign other Variables accordingly.
- Dynamically create the HTML Table Code based on the second of two Recordsets and assign it to a String Variable. Assign other Variables accordingly specific to this Recordset as appropriate.
- Concatenate both String Variables to the HTMLBody Property of an Outlook Item.
- Display the Outlook Window in which two, totally independent HTML Tables are displayed each based on a different Recordset.
- There are a couple of small items to be worked out, one being the relocation of the Header info, but this is the basic concept.
- Download the Attachment to see what I mean, it is fully operational.
- Some Code has intentionally been omitted.
- '--------------------------------------------------------------------------
-
Dim aHead2(1 To 3) As String
-
Dim aRow2(1 To 3) As String
-
Dim aBody2() As String
-
Dim rec2 As DAO.Recordset
-
Dim lCnt2 As Integer
-
-
strSQL2 = "SELECT [First Name], [Last Name],[Job Title] FROM Employees"
-
Set rec2 = db.OpenRecordset(strSQL2, dbOpenDynaset)
-
-
'Create the header row
-
aHead2(1) = "First Name"
-
aHead2(2) = "Last Name"
-
aHead2(3) = "Job Title"
-
-
lCnt2 = 1
-
ReDim aBody2(1 To lCnt2)
-
-
aBody2(lCnt2) = "<HTML><body><table border='2'><tr><th>" & Join(aHead2, "</th><th>") & "</th></tr>"
-
-
If Not (rec2.BOF And rec2.EOF) Then
-
Do While Not rec2.EOF
-
lCnt2 = lCnt2 + 1
-
ReDim Preserve aBody2(1 To lCnt2)
-
aRow2(1) = rec2("First Name")
-
aRow2(2) = rec2("Last Name")
-
aRow2(3) = rec2("Job Title")
-
aBody2(lCnt2) = "<tr><td>" & Join(aRow2, "</td><td>") & "</td></tr>"
-
rec2.MoveNext
-
Loop
-
End If
-
-
'aBody2(lCnt2) = "Hello," & "<br>" & _
-
'"<br>" & _
-
'"Here are the Employee Names that you requested" & "<br>" & _
-
'"<br>" & _
-
aBody2(lCnt2) & "</table></body></html>"
-
'--------------------------------------------------------------------------
-
-
strBody1 = Join(aBody, vbNewLine)
-
olItem.HTMLBody = strBody1 & Join(aBody2, vbNewLine)
-
olItem.display
Sign in to post your reply or Sign up for a free account.
Similar topics
by: David Burson |
last post by:
Hi,
I have a VB.NET windows app that needs to automatically send a simple text
email when my users run a new version of the app for the first time. I
thought this would be simple, but after...
|
by: StevenBarnes |
last post by:
I need to have some .Net code be able to send Email using my ISP's SMTP
server. I found some articles on how to use the MAIL FROM: and RCPT TO:
commands that you can stream to a tcp connection on...
|
by: Mike Charney |
last post by:
Is there a simple way to send SMTP email from Access VBA?
Mike
m charney at dunlap hospital dot org
|
by: markxxiv |
last post by:
How can I send queries, reports, and perhaps forms for one database via email to a colleague who also has Access 2003 and the same database as the one I'm using to create these queries and reports? ...
|
by: Mahernoz |
last post by:
Can i send an email from JavaScript? Is it possible? If yes please the
code to send email using javascript...
|
by: Wells Wang |
last post by:
Hi, Everybody:
Sorry to bother you.
I am trying to use the code below to send an email with asp.net2.0& win
XP. But it failed. On my laptop I can use outlook2003 to send email. If
you are...
|
by: Frinavale |
last post by:
Introduction
Many .NET applications will require an email be sent out for various reasons. This article will give a quick examples on how to send an email using VB.NET. The examples given can...
|
by: chaitanya02 |
last post by:
Hi All,
Well- this question might have appeared several times on this forum- but would appreciate your reply on this:
I have a asp page, where customers login with some username and the pwd,...
|
by: BLUE |
last post by:
I want to send an email from my web service.
I do not want to act like an email client, giving credentials of an existing
email account to send messages: I would like to send my mail directly to...
|
by: Tony M |
last post by:
VS 2005 - XP media - VB .net - winforms - .net 2.0
Just trying to send an email, here is the code and the error message that I
get. I can't figure out how to fix it?
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |