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

Creating a string by looping through records

I sort of know what I need to do, I just can't seem to find any references online that are giving me exactly what I need... Or maybe I'm just not understanding it (which is probably likely).

So here's what I've got:
I have 3 separate tables (TblContactInfo and TblMailingList which hold contact information, and TblEntries with primary key ID that holds the data for each report I want to create and send). TblContactInfo holds names and corresponding email addresses (Primary key - EmailID), and TblMailingList stores which contacts are paired with which report (Primary keys - EmailID and ID).

I need to be able to loop through TblMailingList and be able to add each EmailID to a string that has a given value for the ID field.

Right now, this is what I've put together. I've somehow managed to never need to use a loop before, so the syntax is not familiar to me. LbxReportList is how the value for ID is selected.


Expand|Select|Wrap|Line Numbers
  1. Dim strEmailList As String
  2. Dim rst As DAO.Recordset
  3.  
  4. Set rst = CurrentDb.OpenRecordset("SELECT * FROM TblMailingList "WHERE [ID] = " & Me.LbxReportList)
  5.  
  6. Do Until rst.EOF
  7. strEmailList = strEmailList & rst.Fields(EmailID) & "; "
  8. rst.MoveNext
  9.  
  10. Loop
  11.  
  12. rst.Close
  13. Set rst = Nothing
I'd appreciate any help from anyone who can shed some light on this for me! Thanks!
Jun 2 '12 #1

✓ answered by NeoPa

You need to use :
Expand|Select|Wrap|Line Numbers
  1. strEmailList = strEmailList & rst.Fields("EmailID") & "; "
The existing code is looking for a field which has a name of the value of a variable called EmailID. I suspect you have no such variable.

Please read Before Posting (VBA or SQL) Code for some handy tips that will help you to avoid ever getting into such a situation again. Option Explicit in all your modules is the main point here, but others too, can prove helpful.

5 5609
Mihail
759 512MB
If I understand well your question I think you can solve that more elegant (and easier) by using a sub-report in your main report.
Jun 2 '12 #2
The main reason I was looking at creating a string here is that I want to be able to create a list of email recipients to send via Outlook. I've already got code that successfully exports the report to PDF form, I just want to be able to send that report to the intended recipients in an automated fashion.

Right now, I have this to send the email:

Expand|Select|Wrap|Line Numbers
  1. Set miMail = appOL.CreateItem(olMailItem)
  2. With miMail
  3. .To = strEmailList
  4. .Subject = "NICU Patient Safety Team: End of Cycle Progress Report"
  5. .Body = ""
  6. .ReadReceiptRequested = False
  7. Set oMyAtt = miMail.Attachments.Add("C:\AccessReports\" & strReportTitle & ".pdf")
  8. .Save
  9. End With
  10. GetOut:
  11. Set miMail = Nothing
Unfortunately though, it's not getting that far. Right now, it's hanging up on this line in the original post, and giving me an "Item not found in this collection" error:
Expand|Select|Wrap|Line Numbers
  1. strEmailList = strEmailList & rst.Fields(EmailID) & "; "
Any ideas for this? I totally get your point though... If this was a report, using a subreport to handle this would be 100 times easier!
Jun 2 '12 #3
NeoPa
32,556 Expert Mod 16PB
You need to use :
Expand|Select|Wrap|Line Numbers
  1. strEmailList = strEmailList & rst.Fields("EmailID") & "; "
The existing code is looking for a field which has a name of the value of a variable called EmailID. I suspect you have no such variable.

Please read Before Posting (VBA or SQL) Code for some handy tips that will help you to avoid ever getting into such a situation again. Option Explicit in all your modules is the main point here, but others too, can prove helpful.
Jun 2 '12 #4
And as per usual, NeoPa, you da man!
Jun 3 '12 #5
NeoPa
32,556 Expert Mod 16PB
Very kind of you to say so Jennifer :-)
Jun 3 '12 #6

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

Similar topics

2
by: Greg Lindstrom | last post by:
Hello- I'm creating fixed-length record layouts for various record translations I need to perform. I have been using a home-grown object, "FixedLengthRecord" for about 4 years now and am very...
6
by: Lauren Quantrell | last post by:
I have a table tblCustomers in a one-to-many relationship with table tblProducts. What I want to do is to create a stored procudure that returns a list of each customer in tblCustomers but also...
2
by: Sanjay Asrani | last post by:
I have a table like the following Field1 Field2 Field3 ------ ------- ------ x1 y1 z1 x1 y2 z2 x1 y3 z3 x1 ...
3
by: WC Justice | last post by:
I need to build an UPDATE statement that copies the values of roughly 40 fields from a table that stores standard or default values into a table of specific contracts. There are 8 or so fields in...
1
by: Haim Turjeman | last post by:
i want to create a dynamic collection of strings. the way i know to do this is with ArrayList class stringCol { ArrayList string = new ArrayList(); public string this { get{ return...
1
by: mlangley | last post by:
Hi there. I am trying to figure out a way to create a series of empty records in a database (ACCESS 2003). Basically, the table has 10 years of information by id. However, if there is no ID, then...
2
by: mashimaro | last post by:
I created a form that bound to a query. The form shows the records in tabular view. I want to ask how can I loop through each record to perform my update function?
1
by: edyam | last post by:
Because of a simple cin statement, my program goes into an infinite loop and I'm not sure why. I've used the same code in other programs (only with different variable names and cout statements) and...
2
by: mattandlisa3 | last post by:
I need some assistance. I am creating a database in Access 2003 to track personal biographical information for employees. I have completed the input portion of the database (forms, etc.), but now I...
9
by: sultanofswing | last post by:
I'd like to get the following output from the program below: Ref:total Orig:0 total Dupes:0 total Printed:0 Ref:000046 total Orig:2 total Dupes: 0 total Printed:2 Ref:000077 total Orig:6 total...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
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
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,...
0
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,...
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...

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.