473,405 Members | 2,310 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,405 software developers and data experts.

SendObject Loop does not loop through all records!!

78
I am having trouble with my loop code. The code works very well. However, it only loops through 3 records and then completes without errors. I will post code below. Any help with this would be greatly appreciated.

I am using Windows 2000 with Access 2000, sending email through Outlook 2000.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Form_Load()
  3. On Error GoTo Err_Form_Load
  4.  
  5.     Dim rst As DAO.Recordset
  6.     Dim bkMark As String
  7.     Dim stDocName As String
  8.     Dim strSendTo As String
  9.     Dim strSubject As String
  10.     Dim strMessageText As String
  11.  
  12.     Set rst = Me.Recordset
  13.  
  14.     bkMark = rst.Bookmark
  15.     Me.Bookmark = bkMark
  16.  
  17.     rst.MoveFirst
  18.  
  19.  
  20.     Do Until rst.EOF
  21.  
  22.         stDocName = "Request for Updated PO Info EMAIL"
  23.         strSendTo = Me.Suppliers_EmailAddress
  24.         strSubject = "Wesco Distribution Shipping Update Report"
  25.         strMessageText = "To:  " & Me.SupplierName & vbCrLf _
  26.             & "" & vbCrLf _
  27.             & "Attached is a Shipping Update Report for certain PO numbers." & vbCrLf _
  28.             & "" & vbCrLf _
  29.             & "Please review the attached report and reply back to this email with the requested information." & vbCrLf _
  30.             & "" & vbCrLf _
  31.             & "Thank you," & vbCrLf _
  32.             & "" & vbCrLf _
  33.             & "Wesco Distribution Expediting Department "
  34.  
  35.         DoCmd.SendObject acSendReport, stDocName, acFormatRTF, strSendTo, , , strSubject, strMessageText
  36.  
  37.     rst.MoveNext
  38.  
  39.     Loop
  40.  
  41.     rst.Close
  42.  
  43.     Set rst = Nothing
  44.  
  45.     DoCmd.Close acForm, "Email", acSaveYes
  46.  
  47. Exit_Form_Click:
  48.     Exit Sub
  49.  
  50. Err_Form_Load:
  51.     MsgBox Err.Description
  52.     Resume Exit_Form_Click
  53.  
  54. End Sub
  55.  
  56.  
Please help me figure this out. I am completely boggled by this.

Nick
Mar 31 '08 #1
10 3040
nspader
78
I should also state that the purpose of this code is to first select the supplier and supplier email from a table (only selecting ones that have emails). Then it is to send an email to each supplier with its own report in it.

As of now it works perfectly for the first three records everytime. It sends the report for that supplier to the correct supplier email.

I just cannot figure out why it ends after three records when I know there are 7 recods in the recordset (via form view).

Please help me to finish this DB. I am so close to finishing this.(last piece to put together before it is a finished product)

Thank you in advance (Again)

Nick
Mar 31 '08 #2
Stewart Ross
2,545 Expert Mod 2GB
Hi. At first glance there appear to be no errors in your code. However, at line 11 you are setting the recordset object rst by referring to the recordset property of the form; the norm is to use the recordsetclone method to do so.

Try set rst = Me.Recordsetclone instead and let us know whether this resolves the missing records issue.

If it does not resolve the missing records, you will have to check the processing going on within the loop by setting a breakpoint and checking that all records are being processed (using, say, Debug.Print on individual fields within the loop).

-Stewart
Mar 31 '08 #3
nspader
78
Hi. At first glance there appear to be no errors in your code. However, at line 11 you are setting the recordset object rst by referring to the recordset property of the form; the norm is to use the recordsetclone method to do so.

Try set rst = Me.Recordsetclone instead and let us know whether this resolves the missing records issue.

If it does not resolve the missing records, you will have to check the processing going on within the loop by setting a breakpoint and checking that all records are being processed (using, say, Debug.Print on individual fields within the loop).

-Stewart
I did try RecordsetClone...When I do that it loops on the first Record only.

Also, something I noticed, for multiple suppliers I have the same contact. It seems to stop after repeating the same contact twice in a row...The third file. Any help?
Mar 31 '08 #4
Stewart Ross
2,545 Expert Mod 2GB
Hi again. Recordsetclone is the right way to go. You mention that it only sends one record out when you do so - I've reviewed your code again and notice that you are not reffering to the rst recordset object's fields at all - you are referring to the fields on the current record of your form (see extracts below).
Expand|Select|Wrap|Line Numbers
  1. Do Until rst.EOF
  2. ...
  3. strSendTo = Me.Suppliers_EmailAddress
  4. ...
  5. strMessageText = "To: " & Me.SupplierName & vbCrLf _
  6. ... 
  7. rst.MoveNext
  8. Loop
  9.  
You should surely be referring to rst![Suppliers_EmailAddress] and rst![SupplierName], not exclusively to the form's fields if you are processing the underlying recordset within a loop.

-Stewart
Mar 31 '08 #5
nspader
78
Hi again. Recordsetclone is the right way to go. You mention that it only sends one record out when you do so - I've reviewed your code again and notice that you are not reffering to the rst recordset object's fields at all - you are referring to the fields on the current record of your form (see extracts below).
You should surely be referring to rst![Suppliers_EmailAddress] and rst![SupplierName], not exclusively to the form's fields if you are processing the underlying recordset within a loop.

-Stewart
I placed that into the code and now I get a return saying "Item not Found In This Collection". Any Suggestions?

Nick
Apr 1 '08 #6
nspader
78
I placed that into the code and now I get a return saying "Item not Found In This Collection". Any Suggestions?

Nick
I should have said it is on line srtTo = rst![supplier_emailaddress]
Apr 1 '08 #7
Stewart Ross
2,545 Expert Mod 2GB
I should have said it is on line srtTo = rst![supplier_emailaddress]
Hi. The error means that the field in the underlying recordset table or query is not called by the name listed, so it cannot be found. Could you check what the field name really is?

If you would prefer your DB to be checked by us directly you could Zip a 'sanitised' version of your DB (no sensitive data in it) and attach it as a post if this would help. To do so, after sending a reply use the Edit facilities and Manage Attachments to add an attachment to your post.

-Stewart
Apr 1 '08 #8
nspader
78
Hi. The error means that the field in the underlying recordset table or query is not called by the name listed, so it cannot be found. Could you check what the field name really is?

If you would prefer your DB to be checked by us directly you could Zip a 'sanitised' version of your DB (no sensitive data in it) and attach it as a post if this would help. To do so, after sending a reply use the Edit facilities and Manage Attachments to add an attachment to your post.

-Stewart
Thank you so much for you help. I did realize that it was not named properly and it works like a charm. I do have one question pertaining to this code.

Is there any code to show a message saying "no email addresses on file for selected branch" When I select a branch from the drop down list and it has no files in it?

Something like if BOF><EOF Then show message "..."

Any help is appreaciated as always.

Nick
Apr 1 '08 #9
Stewart Ross
2,545 Expert Mod 2GB
Hi Nick. It's good that it is now working for you!

To check for an empty recordset, output a message and exit from the subroutine enter something like this to do what you want. Place it above the loop (just before the DO UNTIL):
Expand|Select|Wrap|Line Numbers
  1. IF rst.EOF then
  2.   MsgBox "There are no e-mail addresses in this set", vbExclamation, "No e-mail addresses"
  3.   Exit SUB
  4. END IF
-Stewart
Apr 1 '08 #10
nspader
78
Thank you for you help.

I will post my code below as a finished product for this Sub.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Form_Load()
  3. On Error GoTo Err_Form_Load
  4.  
  5.     Dim rst As DAO.Recordset
  6.     Dim bkMark As String
  7.     Dim stDocName As String
  8.     Dim strSendTo As String
  9.     Dim strSubject As String
  10.     Dim strMessageText As String
  11.  
  12.     Set rst = Me.RecordsetClone
  13.  
  14.     If rst.EOF Then
  15.  
  16.         MsgBox "There are no Supplier Reports to Email in this Branch", vbExclamation, "No e-mail addresses"
  17.  
  18.         rst.Close
  19.  
  20.         Set rst = Nothing
  21.  
  22.         DoCmd.Close acForm, "Email", acSaveYes
  23.  
  24.         Exit Sub
  25.  
  26.     End If
  27.  
  28.     Do While rst.EOF = False
  29.         bkMark = rst.Bookmark
  30.         Me.Bookmark = bkMark
  31.  
  32.         stDocName = "Request for Updated PO Info EMAIL"
  33.         strSendTo = rst![EmailAddress]
  34.         strSubject = "Wesco Distribution Shipping Update Report"
  35.         strMessageText = "To:  " & rst![SupplierName] & vbCrLf _
  36.             & "" & vbCrLf _
  37.             & "C/O:  " & rst![ContactName] & vbCrLf _
  38.             & "" & vbCrLf _
  39.             & "Attached is a Shipping Update Report for certain PO numbers." & vbCrLf _
  40.             & "" & vbCrLf _
  41.             & "Please review the attached report and reply back to this email with the requested information." & vbCrLf _
  42.             & "" & vbCrLf _
  43.             & "Thank you," & vbCrLf _
  44.             & "" & vbCrLf _
  45.             & "Wesco Distribution Purchasing Department "
  46.  
  47.         DoCmd.SendObject acSendReport, stDocName, acFormatRTF, strSendTo, , , strSubject, strMessageText
  48.  
  49.     rst.MoveNext
  50.  
  51.     Loop
  52.  
  53.     MsgBox "All emails have been sent to Suppliers", 0, "Email Complete"
  54.  
  55.     rst.Close
  56.  
  57.     Set rst = Nothing
  58.  
  59.     DoCmd.Close acForm, "Email", acSaveYes
  60.  
  61. Exit_Form_Click:
  62.     Exit Sub
  63.  
  64. Err_Form_Load:
  65.     MsgBox Err.Description
  66.     Resume Exit_Form_Click
  67.  
  68. End Sub
  69.  
  70.  
  71.  
Thank you again for all of your help. The forum is fantastic!!!
Apr 1 '08 #11

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

Similar topics

0
by: Tim::.. | last post by:
Hi can someone please give me some help with this little problem I am having with the following loop ...:: CODE ::. < 'Load XM set xml = Server.CreateObject("Microsoft.XMLDOM" xml.async = fals...
4
by: Radu | last post by:
Hi. It seems to be very simple, actually, but I don't know if it is feasible in TSQL. I have a sproc which gathers in one place many calls to different other sprocs, all of them taking a...
2
by: MLH | last post by:
Take a look at the code that follows. Line 110 is the beginning of Do-Loop. Regarding line #220, I find that I'm getting Error #3021 (No Current Record) during execution of line #230. It puzzles me...
7
by: lakepeir | last post by:
Hello, I need help with my for loop. The loop does not end. It should end when i is one less than uBound. What happens is that when i is 1 less than uBound, the loop continues with a weird...
14
by: David | last post by:
Hi, I have a form on which a user can select a checkbox against a record. Each checkbox carries the RecordID of a product. ---------------------------------------------------------------- I...
6
by: kwstriker299 | last post by:
Hello All-- I am trying to loop through all the records in a table named: tbl_Scan_Index. I am using MS Access 2003. Here is my code(VBA): Dim drawer As Integer Dim Folder As Integer Dim...
3
by: barmatt80 | last post by:
I finally got my call to a stored procedure on our db2 to work. However i might have to change what the stored procedure does, if I cannot get it to work how we want. Which i would like to make it...
2
by: Prashant Pradeep | last post by:
HI, I have two tables WORK and EMP. Table work has fields - CaseNo,Date_Act, Handler. Table Emp has one field - EmpName. My field handler should be populated automatically from my table EMP....
2
by: Gavin Sequeira | last post by:
Hi. I have a Main form with a Subform. My Main form generates an ID and some info is passed to the subform alongwith the ID. Lets say some changes are made to the mainform, this info is then added to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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...
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...

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.