Concatenate Email Addresses

S

SoDakRah

I want to read a table of users and concatenate their email addresses into
one long string to address one email instead of individual emails.

Example table A has 10 employees, 2 departments D1, D2

I use a query to open a recordset RST and read through the table extracting
each email for a selected department. strTo = RST.email
Now I want to append the next users email address to the first one.
Something like
strTo = strTo & "," & RST.email

This does not work.

Any help will be appreciated.
 
P

pietlinden

I want to read a table of users and concatenate their email addresses into
one long string to address one email instead of individual emails.

Example table A has 10 employees, 2 departments D1, D2

I use a query to open a recordset RST and read through the table extracting
each email for a selected department.  strTo = RST.email
Now I want to append the next users email address to the first one.  
Something like
strTo = strTo & "," & RST.email

This does not work.

Any help will be appreciated.

It doesn't work because you're not looping anywhere...

dim rs as dao.recordset
set rs=CurrentDB.Querydefs("YourQueryDef").OpenRecordset
do until rs.EOF
strTo = strTo & "," &rs.Fields("EMail")
rs.MoveNext
Loop
strTo=right$(strTo,len(strTo)-1)
 
S

SoDakRah

Sorry, I did have a do...loop in the code but did not include that
information. I was getting an error (Object Required) on the strTo=strTo
line and thought it has something to do with setting a string equal to
itself. Your message made me look very close at my code and I found a
mispelled field name. Is my face red! I corrected that and the loop works
perfectly. Thanks for your assistance.
 
Top