By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,503 Members | 2,788 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,503 IT Pros & Developers. It's quick & easy.

Outlook To: field populates based on a table

100+
P: 283
Hello,

I am using Access to Generate an Outlook Email based on a button click. Currently I have this working with no problem but I want to populate the To: field of the email based on email addresses that are listed in a table instead of hard coding them in. I currently have the below code working but it will only pull in the last email in the table. I was wondering if anyone could help me adjust it so it will loop through the table pulling in all of the addresses?

Apprecaite the help!

Expand|Select|Wrap|Line Numbers
  1. Private Function ToNam() As String
  2.  
  3. Dim db As DAO.Database
  4. Dim rst As DAO.Recordset
  5.  
  6. Set db = CurrentDb()
  7. Set rst = db.OpenRecordset("EmailList")
  8.  
  9. With rst
  10.     .MoveFirst
  11.      Do Until rst.EOF
  12.         If IsNull(.Fields(0)) = False Then
  13.         ToNam = .Fields(0)
  14.         End If
  15.     .MoveNext
  16.    Loop
  17. End With
  18.  
  19. Set rst = Nothing
  20. Set db = Nothing
  21. End Function
  22.  
Jun 20 '12 #1

✓ answered by dsatino

What rabbit said...
ToNam= ToNam & ";" & .fields(0)

that will give you a leading ";" which I don't think bothers Outlook. If it does than you just need to add an IF statement in there.

Share this Question
Share on Google+
4 Replies


Rabbit
Expert Mod 10K+
P: 12,315
You need to append to the variable with each iteration. Right now you're just replacing the value.
Jun 20 '12 #2

100+
P: 283
What do you mean by Append? Like an Append Query?
Jun 20 '12 #3

dsatino
100+
P: 393
What rabbit said...
ToNam= ToNam & ";" & .fields(0)

that will give you a leading ";" which I don't think bothers Outlook. If it does than you just need to add an IF statement in there.
Jun 20 '12 #4

100+
P: 283
Hi dsatino,

very nice my friend that worked perfectly.

Originally I was trying that at then end of the statement

ToNam = .fields(0) & ";"

but was getting no where.

Appreciate the help!!
Slen
Jun 20 '12 #5

Post your reply

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