473,794 Members | 2,752 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SendObject Loop does not loop through all records!!

78 New Member
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 3084
nspader
78 New Member
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 Recognized Expert Moderator Specialist
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.Recordsetclo ne 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 New Member
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.Recordsetclo ne 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 Recognized Expert Moderator Specialist
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_Email Address] 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 New Member
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_Email Address] 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 New Member
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_emaila ddress]
Apr 1 '08 #7
Stewart Ross
2,545 Recognized Expert Moderator Specialist
I should have said it is on line srtTo = rst![supplier_emaila ddress]
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 New Member
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 Recognized Expert Moderator Specialist
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

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

Similar topics

0
1425
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 xml.load(Server.MapPath("ProjectTEST.xml") Dim sDate(200,100
4
2114
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 'StoreGroupe' parameter. I would like to add a case where if the call has NO StoreGroupe parameter, the sproc should LOOP thru all records in table StoreGroupeTable, read the column StoreCode, and pass that value as a param to the other sprocs, as in: ...
2
1796
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 as to Why? I thought if I was on last valid record of RecSet when line #220 executes, I would be sent to process lines after line #400. Am I wrong about that? ==> BEGIN CODE SNIPPET <=== 110 Do Until RecSet.EOF StartAnew:
7
1966
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 value 5432325 (I have no idea how this value is generated, uBound is less than 10.) and then i is equal to zero again. Here's the code: for (int i=0; i < uBound; i++) for (int j=0; j < uBound2; j++) {
14
3094
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 am trying to print the following report:- Details for product 1
6
6920
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 msg As String Dim count As Integer
3
20160
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 work on the sql server side, and not have to change the db2 side as that takes some time from our developers. But this is what i want to do. I have a stored procedure that calls the db2 stored procedure to return 4 leave amounts(@Annual, @Sick,...
2
1625
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. Let us assume there are 100 records in work and 11 records in emp, I need a query / Macro so that 100 Cases is distributed equally among 11 emp.
2
3079
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 the subform as a new record with the same ID (as in the main form) i.e saved as a 2nd record in my subform and will show under the main forms ID as 2 records. There are times when I have to generate the same values of the main form and capture the...
0
9671
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9518
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10433
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10212
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10000
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9035
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6777
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3720
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.