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

Convert Column Data in to CSV string

I have a field of emailAddy in tblMain - consisting of some 100+ email addresses.

I'd like to run a query that pulls each entry and outputs it to a txt/csv file in this format:

emailAddy1,emailAddy2,emailAddy3, etc.

I need all the emails to be in one consecutive string so I can copy/paste into a mass email.

In advance...THANKS!
Dec 5 '09 #1
5 3863
Delerna
1,134 Expert 1GB
Without any consideration as to whether you are wanting to do it in the best way or not.

Have you tried it with VBA?

PSEUDOCODE
Expand|Select|Wrap|Line Numbers
  1. Create a recordset object
  2. query the emails and fill the recordset
  3. create and open a file
  4. loop through the recordset 
  5.    add email from the current record in the recordset plus a comma to the file
  6.    move to next record in the recordset
  7. repeat until end of recordset
  8. close file
  9.  
Dec 6 '09 #2
Just something quick and easy.
Not really caring how it's done....I'll just be copying and pasting the output.

I thought of what you've posted, but not really sure how to approach this.
Dec 6 '09 #3
ADezii
8,834 Expert 8TB
Execute the following code which will produce the desired results, writing them to a File Nnamed EMails.txt in the Root Directory of Drive C:, namely C:\EMails.txt:
Expand|Select|Wrap|Line Numbers
  1. Dim MyDB As DAO.Database
  2. Dim rstEMail As DAO.Recordset
  3. Dim strEMailAddrs As String
  4.  
  5. Set MyDB = CurrentDb
  6. Set rstEMail = MyDB.OpenRecordset("tblMain", dbOpenForwardOnly)
  7.  
  8. Open "C:\EMails.txt" For Output As #1
  9.  
  10. Do While Not rstEMail.EOF
  11.   If Not IsNull(rstEMail![emailAddy]) Then
  12.     strEMailAddrs = strEMailAddrs & rstEMail![emailAddy] & ","
  13.   End If
  14.    rstEMail.MoveNext
  15. Loop
  16.  
  17. strEMailAddrs = Left$(strEMailAddrs, Len(strEMailAddrs) - 1)
  18.  
  19. Print #1, strEMailAddrs
  20.  
  21. rstEMail.Close
  22. Set rstEMail = Nothing
  23. Close #1
Dec 7 '09 #4
Delerna
1,134 Expert 1GB
If adezii's code complains about the recordset object
then you might want to check your references to see that the DAO type library is selected

From the code page of your form
choose the tools menu and the references option

The type library you need is
Microsoft DAO 3.6 Object Library



Not really caring how it's done....I'll just be copying and pasting the output.
And there's nothing wrong with that. If it works and performance is acceptable. By the way I wasn't trying to suggest that this is not the best way, just highlighting that I was simply answering your question, as asked.
Compare adezii's code and my pseudo code and you will see similarities.
I like to write my programs with pseudo code (commented out of course)
and then write the actual code around the pseudo code...automatic comments :)
Dec 7 '09 #5
Thanks folks!

ADezii's solution was just what I was looking for!!!

Thanks again.
Cheers!
Dec 8 '09 #6

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

Similar topics

4
by: alederer | last post by:
Hallo! I need to convert the values of a varchar (..) for bit data column to a string which can be stored in a normal varchar column (with additional information). Is there a function in db2...
2
by: KB | last post by:
Hi guys, In my DataGrid I have a column that displays decimal values as currency ( I set the Data Formatting expression of that column to {0:C}). So the actual string displayed in the grid looks...
2
by: Steve | last post by:
I have a very simple datatable of 1 column which I retrieve from a database, call it 'data'. Dim data As Data.DataTable data = myobject.mymethod(parameter) I want to now turn this 'data' into...
5
by: Learner | last post by:
Hello, Here is the code snippet I got strucked at. I am unable to convert the below line of code to its equavalent vb.net code. could some one please help me with this? static public...
1
by: neeraj | last post by:
Hi All Can any give me the code for convert "DataColumn" data type of "DataTable". Even if data table already populated (have data) Actually I am creating one search module which searches the...
2
by: Ch Pravin | last post by:
Hi All: I am having the following xml which i need to convert to excel using xslt. Please help me out. Afghanistan.xml <?xml version="1.0" encoding="utf-16"?> <Languages...
2
by: CodeMonkey775 | last post by:
I'm having problems passing a variable to a method which is executed and compiled using CodeDom. The situation is I have a List<CellData> with cells, each containing a formula (like Excel). I am...
7
by: crs27 | last post by:
Hai, Im new to sql server... I want to convert a field in a table to DateTime. The column(Column Name-DDateTime , Data type String) has data in this format 01-04-2008 15:12:52 i want...
12
by: Miro | last post by:
How can I convert this part of the line: Me.dgvmyData.Columns.Item("txtCellName") ' "txtCellName" which is within this line - Me.dgvmyData.Sort(Me.dgvmyData.Columns.Item("txtCellName"),...
9
by: myotheraccount | last post by:
Hello, Is there a way to convert a DataRow to a StringArray, without looping through all of the items of the DataRow? Basically, I'm trying to get the results of a query and put them into a...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.