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. -
-
Private Sub Form_Load()
-
On Error GoTo Err_Form_Load
-
-
Dim rst As DAO.Recordset
-
Dim bkMark As String
-
Dim stDocName As String
-
Dim strSendTo As String
-
Dim strSubject As String
-
Dim strMessageText As String
-
-
Set rst = Me.Recordset
-
-
bkMark = rst.Bookmark
-
Me.Bookmark = bkMark
-
-
rst.MoveFirst
-
-
-
Do Until rst.EOF
-
-
stDocName = "Request for Updated PO Info EMAIL"
-
strSendTo = Me.Suppliers_EmailAddress
-
strSubject = "Wesco Distribution Shipping Update Report"
-
strMessageText = "To: " & Me.SupplierName & vbCrLf _
-
& "" & vbCrLf _
-
& "Attached is a Shipping Update Report for certain PO numbers." & vbCrLf _
-
& "" & vbCrLf _
-
& "Please review the attached report and reply back to this email with the requested information." & vbCrLf _
-
& "" & vbCrLf _
-
& "Thank you," & vbCrLf _
-
& "" & vbCrLf _
-
& "Wesco Distribution Expediting Department "
-
-
DoCmd.SendObject acSendReport, stDocName, acFormatRTF, strSendTo, , , strSubject, strMessageText
-
-
rst.MoveNext
-
-
Loop
-
-
rst.Close
-
-
Set rst = Nothing
-
-
DoCmd.Close acForm, "Email", acSaveYes
-
-
Exit_Form_Click:
-
Exit Sub
-
-
Err_Form_Load:
-
MsgBox Err.Description
-
Resume Exit_Form_Click
-
-
End Sub
-
-
Please help me figure this out. I am completely boggled by this.
Nick
10 3084
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
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
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?
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).
-
Do Until rst.EOF
-
...
-
strSendTo = Me.Suppliers_EmailAddress
-
...
-
strMessageText = "To: " & Me.SupplierName & vbCrLf _
-
...
-
rst.MoveNext
-
Loop
-
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
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
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]
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
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
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): - IF rst.EOF then
-
MsgBox "There are no e-mail addresses in this set", vbExclamation, "No e-mail addresses"
-
Exit SUB
-
END IF
-Stewart
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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:
...
|
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:
|
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++)
{
|
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
| |
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
|
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,...
|
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.
|
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...
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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...
|
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();...
|
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...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |