473,395 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

send a report as the body of an email

Hi All,
I'm using a code somebody posted here. I extract the records from a
query which gave me just the entries for the current date, there will
be maximum 5-6 entries per days and I need to send them as the body of
an email. The code partially works and what happens is that it will
send an email per every record when what I need is to send just an
email, at the end of the day, including all the entries made(Rack,
CompanyName and ComponentName are the records from the query). I want
to try moving "pst.send" below ".MoveNext" this is an idea that just
ocurrs to me, I don't know it will works, I just started taking vb
classes, kind of a beginner. Here is the code I'll appreciate if
someone can help me:
************************************************** **************************
Sub sendEmail()
Dim olk As Outlook.Application
Dim pst As Outlook.MailItem
Dim rst As Recordset
Dim db As Database
Dim usr As Variant
Set db = CurrentDb
Set rst = db.OpenRecordset("ASPComponentShipped")
Set olk = CreateObject("outlook.application")

With rst
Do Until .EOF
usr = "pi************@epi.epson.com"
Set pst = olk.CreateItem(olMailItem)

With pst
.ReadReceiptRequested = False
.To = usr
.Subject = "ASP Component Shipped"
.Body = "EAI Gemini Support," & vbCrLf & vbCrLf &
"The following ASP component requests were fullfilled today:" _
& vbCrLf & vbCrLf & Rack & " " & Companyname & " "
& ComponentName _
& vbCrLf & vbCrLf & "Sincerely," & vbCrLf & "EPI
Gemini Support"
.Send
End With

.MoveNext
Loop
End With
End Sub
Nov 12 '05 #1
2 8731
"pilar" <ca***********@hotmail.com> wrote in message
news:6b**************************@posting.google.c om...
Hi All,
I'm using a code somebody posted here. I extract the records from a
query which gave me just the entries for the current date, there will
be maximum 5-6 entries per days and I need to send them as the body of
an email. The code partially works and what happens is that it will
send an email per every record when what I need is to send just an
email, at the end of the day, including all the entries made(Rack,
CompanyName and ComponentName are the records from the query). I want
to try moving "pst.send" below ".MoveNext" this is an idea that just
ocurrs to me, I don't know it will works, I just started taking vb
classes, kind of a beginner. Here is the code I'll appreciate if
someone can help me:
************************************************** ************************** Sub sendEmail()
Dim olk As Outlook.Application
Dim pst As Outlook.MailItem
Dim rst As Recordset
Dim db As Database
Dim usr As Variant
Set db = CurrentDb
Set rst = db.OpenRecordset("ASPComponentShipped")
Set olk = CreateObject("outlook.application")

With rst
Do Until .EOF
usr = "pi************@epi.epson.com"
Set pst = olk.CreateItem(olMailItem)

With pst
.ReadReceiptRequested = False
.To = usr
.Subject = "ASP Component Shipped"
.Body = "EAI Gemini Support," & vbCrLf & vbCrLf &
"The following ASP component requests were fullfilled today:" _
& vbCrLf & vbCrLf & Rack & " " & Companyname & " "
& ComponentName _
& vbCrLf & vbCrLf & "Sincerely," & vbCrLf & "EPI
Gemini Support"
.Send
End With

.MoveNext
Loop
End With
End Sub

I would start by splitting this code into parts. One of them would be a
function to retrieve the text from the tables:

Function GetShipText() As String

On Error GoTo Err_Handler

Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strInfo As String

Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("ASPComponentShipped", dbOpenForwardOnly,
dbReadOnly)

While Not rst.EOF
strInfo = strInfo & rst!Rack & vbTab
strInfo = strInfo & rst!CompanyName & vbTab
strInfo = strInfo & rst!ComponentName & vbCrLf
rst.MoveNext
Wend

GetShipText = strInfo

Exit_Handler:

If Not rst Is Nothing Then
rst.Close
Set rst = Nothing
End If

If Not dbs Is Nothing Then
Set dbs = Nothing
End If

Exit Function

Err_Handler:
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Function

Then you could have in your sub:

Dim strBody

strBody = GetShipText()

If Len(strBody) = 0 Then
strBody = "Nothing shipped today"
Else
strBody = "The following ASP component requests were fullfilled today:"
& vbcrlf & strBody
End if

....
....
etc

Nov 12 '05 #2
"Fletcher Arnold" <fl****@home.com> wrote in message news:<bm**********@hercules.btinternet.com>...
"pilar" <ca***********@hotmail.com> wrote in message
news:6b**************************@posting.google.c om...
Hi All,
I'm using a code somebody posted here. I extract the records from a
query which gave me just the entries for the current date, there will
be maximum 5-6 entries per days and I need to send them as the body of
an email. The code partially works and what happens is that it will
send an email per every record when what I need is to send just an
email, at the end of the day, including all the entries made(Rack,
CompanyName and ComponentName are the records from the query). I want
to try moving "pst.send" below ".MoveNext" this is an idea that just
ocurrs to me, I don't know it will works, I just started taking vb
classes, kind of a beginner. Here is the code I'll appreciate if
someone can help me:

************************************************** **************************
Sub sendEmail()
Dim olk As Outlook.Application
Dim pst As Outlook.MailItem
Dim rst As Recordset
Dim db As Database
Dim usr As Variant
Set db = CurrentDb
Set rst = db.OpenRecordset("ASPComponentShipped")
Set olk = CreateObject("outlook.application")

With rst
Do Until .EOF
usr = "pi************@epi.epson.com"
Set pst = olk.CreateItem(olMailItem)

With pst
.ReadReceiptRequested = False
.To = usr
.Subject = "ASP Component Shipped"
.Body = "EAI Gemini Support," & vbCrLf & vbCrLf &
"The following ASP component requests were fullfilled today:" _
& vbCrLf & vbCrLf & Rack & " " & Companyname & " "
& ComponentName _
& vbCrLf & vbCrLf & "Sincerely," & vbCrLf & "EPI
Gemini Support"
.Send
End With

.MoveNext
Loop
End With
End Sub

I would start by splitting this code into parts. One of them would be a
function to retrieve the text from the tables:

Function GetShipText() As String

On Error GoTo Err_Handler

Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strInfo As String

Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("ASPComponentShipped", dbOpenForwardOnly,
dbReadOnly)

While Not rst.EOF
strInfo = strInfo & rst!Rack & vbTab
strInfo = strInfo & rst!CompanyName & vbTab
strInfo = strInfo & rst!ComponentName & vbCrLf
rst.MoveNext
Wend

GetShipText = strInfo

Exit_Handler:

If Not rst Is Nothing Then
rst.Close
Set rst = Nothing
End If

If Not dbs Is Nothing Then
Set dbs = Nothing
End If

Exit Function

Err_Handler:
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Function

Then you could have in your sub:

Dim strBody

strBody = GetShipText()

If Len(strBody) = 0 Then
strBody = "Nothing shipped today"
Else
strBody = "The following ASP component requests were fullfilled today:"
& vbcrlf & strBody
End if

...
...
etc


Thanks Arnold, After a few modifications it works great!
Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: rob | last post by:
I have an win form app from which I want to be able to send bug reports. My first approach was something like: SmtpClient client = new SmtpClient( ????? ); MailAddress from = new...
10
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
1
by: Mr T | last post by:
I know how to send email from Access and I know how to create a custom form in Outlook. but.... How do I put the email info from Access into the Outlook custom form ??? Dim MyDB As Database Dim...
0
by: Nanker | last post by:
I would like to integrate Reporting Services reports into an existing email messaging framework using .NET 1.1 (both to leverage the existing framework and since the error reporting by Reporting...
0
by: dreamsoul620 via AccessMonster.com | last post by:
Hi all! I'm trying to set up an email application for my database. I tried linking to my Outlook address book, but when reading from the table, I receive an error message saying I need to restart...
1
by: pixie | last post by:
Hi. Access 2003. The database stores contract information. I have a query for each person that is responsible for contracts. The query checks to see if there are reports due either this week,...
5
by: jsd219 | last post by:
is there not an easy way to simply send the contents of a page in the body of an email? i.e. i have a report.php that pulls from a mysql db. i need to be able to send the displayed file right in...
1
by: sxwend | last post by:
I am trying to use the following post results (http://www.thescripts.com/forum/thread189759.html) and add another requirement. I need to send the results to just the email addresses that the query...
0
by: Kristoph | last post by:
Hello, I would like to send an Access report as text in the body of a Lotus Notes email. Currently I am using DoCmd.SendObject which sends the report as a text attachment just great! But,...
0
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
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...
0
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
tracyyun
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.