473,410 Members | 1,873 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,410 software developers and data experts.

Sendobject attaches incorrect report to emails

3
This Sub emails accounting statements to all customers that are flagged for this delivery type. The function calling the Sub merely loops through the customer table and passes the variables.

The code works perfectly if I step through it or run it for a single customer.

When run for real it attaches the incorrect statement to 90%+ of emails.

By inserting a couple of 1 to 25m counters to slow everything down I can get
90-95% accuracy.

Any suggestions or comments would be welcome:


Sub subemail(numb, add, acname)

Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strSQL As String

Set db = CurrentDb()
Set qdf = db.QueryDefs("autostat")

strSQL = "SELECT main.Account, main.Name, cust.ac_add1, cust.ac_add2, cust.ac_add3, cust.ac_add4, RTrim([ac_town]) & ' ' & [ac_zip] AS town, cust.ac_country, cust.ac_zip, slbals.Date, slbals.Type, LTrim([ref]) AS Refe, slbals.Des, slbals.Original, IIf([original]>0,[original],'') AS dr, IIf([original]<0,[original],'') AS cr, slbals.Outstanding, slbals.age, main.[statement output]" & _
"FROM (main LEFT JOIN cust ON main.Account = cust.accno) LEFT JOIN slbals ON main.Account = slbals.Account " & _
"WHERE (((main.Account) = '" & numb & "') And ((slbals.Outstanding) <> 0))" & _
"ORDER BY slbals.Date;"

qdf.SQL = strSQL

cr = Chr(13)
mailmsg = numb & " " & acname & cr & cr & "Your statement of account is attached" & cr & cr & "Regards" & cr & cr & "Elric" & cr & "Company name"

DoCmd.SendObject acSendReport, "email_statement", acFormatRTF, add, , , "Statement of account", mailmsg, False

Set db = Nothing
Set qdf = Nothing
End Sub
May 29 '07 #1
6 1209
JConsulting
603 Expert 512MB
This Sub emails accounting statements to all customers that are flagged for this delivery type. The function calling the Sub merely loops through the customer table and passes the variables.

The code works perfectly if I step through it or run it for a single customer.

When run for real it attaches the incorrect statement to 90%+ of emails.

By inserting a couple of 1 to 25m counters to slow everything down I can get
90-95% accuracy.

Any suggestions or comments would be welcome:


Sub subemail(numb, add, acname)

Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strSQL As String

Set db = CurrentDb()
Set qdf = db.QueryDefs("autostat")

strSQL = "SELECT main.Account, main.Name, cust.ac_add1, cust.ac_add2, cust.ac_add3, cust.ac_add4, RTrim([ac_town]) & ' ' & [ac_zip] AS town, cust.ac_country, cust.ac_zip, slbals.Date, slbals.Type, LTrim([ref]) AS Refe, slbals.Des, slbals.Original, IIf([original]>0,[original],'') AS dr, IIf([original]<0,[original],'') AS cr, slbals.Outstanding, slbals.age, main.[statement output]" & _
"FROM (main LEFT JOIN cust ON main.Account = cust.accno) LEFT JOIN slbals ON main.Account = slbals.Account " & _
"WHERE (((main.Account) = '" & numb & "') And ((slbals.Outstanding) <> 0))" & _
"ORDER BY slbals.Date;"

qdf.SQL = strSQL

cr = Chr(13)
mailmsg = numb & " " & acname & cr & cr & "Your statement of account is attached" & cr & cr & "Regards" & cr & cr & "Elric" & cr & "Company name"

DoCmd.SendObject acSendReport, "email_statement", acFormatRTF, add, , , "Statement of account", mailmsg, False

Set db = Nothing
Set qdf = Nothing
End Sub
the pause is necessary in order to give it time to create the report and attach it.


put this at the top of a code module just under the Option compare statement

Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Dim lmilliseconds As Long


to use it,

Sleep(2000) <-- about two seconds
May 29 '07 #2
puppydogbuddy
1,923 Expert 1GB
You have "add" for the "To" Argument...Shouldn't the AccName go there?

DoCmd.SendObject acSendReport, "email_statement", acFormatRTF, add, , , "Statement of account", mailmsg, False

http://www.databasedev.co.uk/sendobject.html


Also:
have you tried a different sort order (AccNo for instance)? That may have some effect.
May 29 '07 #3
Elric
3
the pause is necessary in order to give it time to create the report and attach it.


put this at the top of a code module just under the Option compare statement

Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Dim lmilliseconds As Long


to use it,

Sleep(2000) <-- about two seconds
Thanks for the reply. Unfortunately 2 seconds makes no difference although I could increase the value.

I need to know the delay period that will guarantee all reports will be attached to the correct email or alternative approaches to either the task itself or to giving Access the opportunity to get it consistently right. I've tried numerous methods and none give 100%.

My problem is that I don't understand the mechanisms involved which makes it difficult to provide a perfect solution.
May 30 '07 #4
JConsulting
603 Expert 512MB
Thanks for the reply. Unfortunately 2 seconds makes no difference although I could increase the value.

I need to know the delay period that will guarantee all reports will be attached to the correct email or alternative approaches to either the task itself or to giving Access the opportunity to get it consistently right. I've tried numerous methods and none give 100%.

My problem is that I don't understand the mechanisms involved which makes it difficult to provide a perfect solution.
we would all enjoy the perfect mechanism...unfortunately for us, we have no idea how large your reports are, how fast your machine is, or how quickly e-mails are created for you.

So for us...anything we tell you would be a wild guess.

The problem IS one of timing. your method is fine...your code is ok. you prove it works 90% of the time. So perhaps you can set the variable sleep based on a recordcount in the report you're outputting. But that's as far as the Access automation can go from a timing standpoint.

You still have environmental considerations outside of Access.

I would say give it your best estimate.
J
Jun 2 '07 #5
Elric
3
Bog standard Dell dimension E521(a couple of months old) , XP, Access 2003 and Thunderbird as emailer. Reports are mostly a single A4 page.

I figure that Access must write the report to a temporary file before attaching it and if I knew where/how then I could, at least, delete the file before creating the next one; this might still be problematic but customers will not get the wrong statement.

I wonder if my coding approach is not ideal, I cannot believe that I'm the only one to have tried producing invoice/statements (or anything else) this way and I can't find any complaints similar to mine.
Jun 4 '07 #6
JConsulting
603 Expert 512MB
Bog standard Dell dimension E521(a couple of months old) , XP, Access 2003 and Thunderbird as emailer. Reports are mostly a single A4 page.

I figure that Access must write the report to a temporary file before attaching it and if I knew where/how then I could, at least, delete the file before creating the next one; this might still be problematic but customers will not get the wrong statement.

I wonder if my coding approach is not ideal, I cannot believe that I'm the only one to have tried producing invoice/statements (or anything else) this way and I can't find any complaints similar to mine.
the only other thing I can suggest here is that you perform a Dcount on the QDF before you open the report with it. I of course can't see your data, so this may not be an issue, but if you're trying to send a blank report, there can be a problem with report generation.

A simple if statement would bypass the current loop to move to the next if the report is blank.

J
Jun 4 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Fred | last post by:
I want to insert DHL and FedEx tracking links with the waybill numbers in the body of emails I am sending using sendobject. I am not sending attachments. DHL and FedEx use long links that...
0
by: Mark C | last post by:
All, I have an Access 97 database that runs a sendobject macro that emails a report as an rtf file to a specific distribution list. Every so often the email gets created with 2 attachments. One...
3
by: Fred Zuckerman | last post by:
Hello All, I had written a quick email procedure for a client that uses DoCmd.SendObject. However they have the SR-1 version of Access 2K. They do not have the SP-3 upgrade. The procedure does...
2
by: Andy_Khosravi | last post by:
I posted this question about two days ago, but for some reason it never actually got put up. I couldn't' find it with searches, so I am re-posting it now. I apologize if this is a double post. ...
4
by: BigAnthony | last post by:
Hi I am helping my sister with an Access database someone wrote for her. I was wondering if someone a lot more knowledgeable than me, could provide some help and advice - I don't have that much...
4
by: jBunton | last post by:
I am using send object to generate emails BUT it works once then not again until I close and reopen my application. Thus in the code below only 1 email is generated - doesn't matter which of the...
1
by: NeoDeGenero | last post by:
I have a little VBA/Access - Reports problem and I’m not sure on how to approach it: I am trying to send a Report generated by MS Access via email through the command SendObject. ...
2
by: craigcain | last post by:
Hi there, I use a form for creating orders that I need to send to clients via email. For this I have a command button which attaches a report (which looks exactly the same as the form) to email in...
11
by: nspader | last post by:
OK, So i have used the help of a few people on here to get the code below running properly. It has run great for a little while. Now when I send emails using code below, I sometimes get a Reserved...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.