Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 29th, 2006, 02:50 PM
Authorized User
 
Join Date: Feb 2004
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to chacquard
Default Creating table with SQL to transfer to a CSV

hello,

I use a huge query to add records to a table (previously emptied) that I export as a CSV. This CSV is now too big. It has information on events. My boss wants me to create a csv for each event name.

So, if I have:

circus1 july 1
circus1 july 2
circus1 july 3
circus2 august 1
circus2 august 2
...

I now need to create circus1.csv and circus2.csv

How can I do it with Access ?

I have tried:

strSQL = "SELECT DISTINCT EVENT.EventName INTO " & [EventName] &" "& _
"FROM EVENT;"

but it doesn't work... :(

have any suggestions ?????

Thank you!!

 
Old June 30th, 2006, 07:25 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

You will have to run a process.

I would suggest creating a query on the EventName column, and selecting Distinct records, so your query output looks like this:

Circus1
Circus2
etc.

Then run a process that loops through each event in this query. From the process, call your current giant query where EventName = the currnet event name in your process. Alternatively, you can call all the event names from the EventName query into an array, and then loop through the array.

Then base your csv file on the name of the current event name.

SO it can be done quite easily. How much code help do you need? I should have time to help you get this working today.

mmcdonal
 
Old June 30th, 2006, 07:31 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Code outline:

Create Connection
Create Recordset on EventName query
MoveFirst
Do Until rs.EOF
  sEvent = rs.Event
  sLink = "[EventName] = & "'" & sEvent & "'"
  sCSVFileName = sEvent & ".csv"
  DoCmd.OpenQuery "qryGiantQuery", , sLink
  DoCmd. ' create text file using sCSVFileName and overwrite any existing copies
  rs.MoveNext
Loop

HTH

mmcdonal





Similar Threads
Thread Thread Starter Forum Replies Last Post
Get table records into Txt or CSV format kapi.goel SQL Language 0 April 10th, 2006 01:47 AM
create CSV flat file from mysql table pb MySQL 1 September 21st, 2005 10:51 AM
csv file into access table with vba Perseus Access VBA 2 September 14th, 2005 02:57 PM
Sql a .csv file langer123 Classic ASP Basics 2 April 18th, 2005 08:55 AM
Transfer SQL Database FROM One SQL PC To Another Israr SQL Server 2000 3 February 2nd, 2005 01:33 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.