473,322 Members | 1,719 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,322 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 8724
"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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.