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 3042
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.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
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?
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_EmailAddress] 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_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
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]
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
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
Thank you for you help.
I will post my code below as a finished product for this Sub. -
-
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.RecordsetClone
-
-
If rst.EOF Then
-
-
MsgBox "There are no Supplier Reports to Email in this Branch", vbExclamation, "No e-mail addresses"
-
-
rst.Close
-
-
Set rst = Nothing
-
-
DoCmd.Close acForm, "Email", acSaveYes
-
-
Exit Sub
-
-
End If
-
-
Do While rst.EOF = False
-
bkMark = rst.Bookmark
-
Me.Bookmark = bkMark
-
-
stDocName = "Request for Updated PO Info EMAIL"
-
strSendTo = rst![EmailAddress]
-
strSubject = "Wesco Distribution Shipping Update Report"
-
strMessageText = "To: " & rst![SupplierName] & vbCrLf _
-
& "" & vbCrLf _
-
& "C/O: " & rst![ContactName] & 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 Purchasing Department "
-
-
DoCmd.SendObject acSendReport, stDocName, acFormatRTF, strSendTo, , , strSubject, strMessageText
-
-
rst.MoveNext
-
-
Loop
-
-
MsgBox "All emails have been sent to Suppliers", 0, "Email Complete"
-
-
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
-
-
-
Thank you again for all of your help. The forum is fantastic!!!
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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....
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
| |