473,395 Members | 1,949 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,395 software developers and data experts.

Outlook To: field populates based on a table

283 100+
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.

4 1919
Rabbit
12,516 Expert Mod 8TB
You need to append to the variable with each iteration. Right now you're just replacing the value.
Jun 20 '12 #2
slenish
283 100+
What do you mean by Append? Like an Append Query?
Jun 20 '12 #3
dsatino
393 256MB
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
slenish
283 100+
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

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

Similar topics

3
by: Ken Wilkins | last post by:
Is there a way to add a field to a table when the same one is created in another table? I'm working with keeping track of software for different versions of OS. If I add a field to the Win98...
13
by: Peter | last post by:
Can anyone tell me how to change the data type of a field in a table created with a make table query? The field is a binary and must be changed to text. alternately does anyone know how to specify...
13
by: MLH | last post by:
I have a form with two controls: !! - combo box !! - text box A button on the form tries to run this SQL when clicked... INSERT INTO BodyMsgsSent (ToWhom, BodyText) SELECT DISTINCTROW !! AS...
7
by: Amy | last post by:
I'm trying to add an autoincrementing id to a table based on an existing field Name, but Name has duplicated records. How can I do that in ACCESS? Thanks. Amy
7
by: No Spam | last post by:
Dear Access 2003 users, Can anyone assist me with creating either code (preferred) or a query that would remove a single field (called ID) from a table? And as a bonus question, can anyone...
1
by: LurfysMa | last post by:
I am working on an electronic flashcard program. Most of the subjects are simple lists of questions and answers. Those seem to be working. Some of the "subjects" have "categories" of questions. ...
4
by: andymcintosh85 | last post by:
Hi, I have a textbox in a form which is being automatically populated form a bound column in a combobox on the same form. What i would like to do is to populate a field in a table based on the...
1
by: solar | last post by:
Is there any way to refer to figure in the frist row of the field in the table. The field is called afid.For example, if the figure in the first row is 1, or afid = 1, then to delete all the other...
4
by: trixxnixon | last post by:
i have a field on a form where a calculation is displayed. The field calculates the number of business days a request is due based on a priority level chosen from a drop down box. i want to save...
3
by: DaveRook | last post by:
Hi I think I'm just after advice on best practice with this! I have a database which has 2 tables. The first table has ID, Name, Address and the second table has ID and JobType. Table 02...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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:
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...
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
agi2029
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,...

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.