473,804 Members | 4,005 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
10 3087
nspader
78 New Member
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
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
2115
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
1799
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
6924
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
1628
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
9579
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
10330
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...
1
10319
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10076
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...
1
7616
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6851
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
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4297
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3816
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.