I found this code while doing a search and since I'm not familiar with recordsets I am at a loss. I did some additional searches on recordsets and found lots of useful information,but none that entirely answered my questions.
1. I am trying to include the entire recordset or query in the body of an email the following just includes the first record of fieid1
2. Can you also include the field names of the table you are trying to include?
3. Basically, I would like to include the query "as-is" in the body of the email
4. Can there also be additional fixed text preceeding the inclusion of this table?
5. Can the e-mail format be coded as plain text vs. HTML?
Any help would be appreciated.
**********************************************************
Public Sub SendMail()
Dim outApp As Outlook.Application
Dim outItem As Outlook.MailItem
Dim strEMailMsg As String ' message text
Dim Db as Dao.Database
Dim Rst as Dao.Recordset
' SET YOUR DB INSTANCE
Set Db = Currentdb
'CREATE YOUR RECORDSET
Set Rst = Db.Openrecordset("MyQuery")
' Use your details from the recordset
strEMailMsg = Rst![Field1]
Set outApp = New Outlook.Application
Set outItem = outApp.CreateItem(olMailItem)
With outItem
.To = "Anybody"
.Subject = "Test"
.HTMLBody = strEMailMsg
.Display
End With
Set Db = Nothing
Set Rst = Nothing
Set outItem = Nothing
Set outApp = Nothing
End Sub
1. I am trying to include the entire recordset or query in the body of an email the following just includes the first record of fieid1
2. Can you also include the field names of the table you are trying to include?
3. Basically, I would like to include the query "as-is" in the body of the email
4. Can there also be additional fixed text preceeding the inclusion of this table?
5. Can the e-mail format be coded as plain text vs. HTML?
Any help would be appreciated.
**********************************************************
Public Sub SendMail()
Dim outApp As Outlook.Application
Dim outItem As Outlook.MailItem
Dim strEMailMsg As String ' message text
Dim Db as Dao.Database
Dim Rst as Dao.Recordset
' SET YOUR DB INSTANCE
Set Db = Currentdb
'CREATE YOUR RECORDSET
Set Rst = Db.Openrecordset("MyQuery")
' Use your details from the recordset
strEMailMsg = Rst![Field1]
Set outApp = New Outlook.Application
Set outItem = outApp.CreateItem(olMailItem)
With outItem
.To = "Anybody"
.Subject = "Test"
.HTMLBody = strEMailMsg
.Display
End With
Set Db = Nothing
Set Rst = Nothing
Set outItem = Nothing
Set outApp = Nothing
End Sub