Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I string the results of a query in VBA?

Status
Not open for further replies.

kathybob

Instructor
Nov 23, 2002
2
US
I have set up a process that automatically generates an email in Microsoft Access 2000. I am very new to Visual Basic, and have only learned what I know from the help function. When generating an email, I can set a To: list variable to a hardcoded literal, but I want to string the results of another query that has been opened into this variable. I want to concatenate each of the To: list IDs with a semicolon, then the next ID, semicolon, etc. To get by for now, I generate the email and cut and paste the list from the open query into my To: line. I'm a mainframe programmer, so I believe there has to be a way to populate this To: list variable from the results of a query. Thanks in advance for any tips to this novice.
 
I think you are trying to use the wrong method (assuming you are using Outlook). Let VBA do the job. The usual way of adding Recipients is something like this partial code :-

'------------------------------------------
Dim MyRecipients As Object
'- NEW MAIL
Set MyMail = CreateObject("Outlook.application")
Set MyItem = MyMail.createitem(olmailitem)
Set MyAttachments = MyItem.attachments
Set MyRecipients = MyItem.recipients
'------------------------------------------
'- RECIPIENTS
For rw = 1 To Addresses.Rows.Count
MailRecipient = Addresses.Cells(rw, 1).Value
MyRecipients.Add (MailRecipient)
Next
'-----------------------------------------------------

Where MailRecipient is a string variable and Addresses is a named worksheet range, but couldbe adapted to Access table data.

Regards
BrianB
** Let us know if you get something that works !
================================
 
I'm using Lotus Notes. Will this method work?
 
Hallo...
I have the same problem, but my data are within a query populating a form... basically my type of database is a sort of telephone directory ... I want to concatenate the email addresses of the records I get, to use later for sending a unique email...

can you explain me how to do??

thanks
Marco
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top