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

Exporting to CSV

Hi,

I have a table which is based on a query that I want to export to a csv
file on a regular basis.The table has 15 columns and each column is
populated fully.

So the table looks something like

Heading1 Heading2 Heading3 ...
aa bb cc
aa bb cc
aa bb cc

My problem is that, in the resulting CSV I need to preceed the columns
from the table with 2 extra columns the first row of which contains
static text i.e. this text will always be the same regardless of the
contents of the table.

So the resulting CSV would look something like:

NewCol1 NewCol2 Heading1 Heading2 Heading3 ...
SA 3357 aa bb cc
aa bb cc
aa bb cc

Could anyone suggest how I can add these 2 columns to the CSV file and
only have the static text on the first row (Note the text has to be on
in the same row as the first row of the table).

Thanks for any help

PC

Jul 13 '06 #1
3 1716
pmc1 wrote:
Hi,

I have a table which is based on a query that I want to export to a csv
file on a regular basis.The table has 15 columns and each column is
populated fully.

So the table looks something like

Heading1 Heading2 Heading3 ...
aa bb cc
aa bb cc
aa bb cc

My problem is that, in the resulting CSV I need to preceed the columns
from the table with 2 extra columns the first row of which contains
static text i.e. this text will always be the same regardless of the
contents of the table.

So the resulting CSV would look something like:

NewCol1 NewCol2 Heading1 Heading2 Heading3 ...
SA 3357 aa bb cc
aa bb cc
aa bb cc

Could anyone suggest how I can add these 2 columns to the CSV file and
only have the static text on the first row (Note the text has to be on
in the same row as the first row of the table).

Thanks for any help

PC
Make your query a union
Select "" As Col1, "" As Col2, Name, Addr from Test
Union
Select "SA" As Col1, "3357" As Col2, "" As Head1....From Test

Then futz with how you want it ordered so that it floats to the top.
Jul 13 '06 #2
Thanks for you reply.

This works to a point. The issue I have is that the first row only
contains the static text and each column in the first row there after
is blank. I need the first row of the resulting recordset to contain
both the static text AND the first row of the original table.

Any suggestions

Thanks again.

...pc

salad wrote:
pmc1 wrote:
Hi,

I have a table which is based on a query that I want to export to a csv
file on a regular basis.The table has 15 columns and each column is
populated fully.

So the table looks something like

Heading1 Heading2 Heading3 ...
aa bb cc
aa bb cc
aa bb cc

My problem is that, in the resulting CSV I need to preceed the columns
from the table with 2 extra columns the first row of which contains
static text i.e. this text will always be the same regardless of the
contents of the table.

So the resulting CSV would look something like:

NewCol1 NewCol2 Heading1 Heading2 Heading3 ...
SA 3357 aa bb cc
aa bb cc
aa bb cc

Could anyone suggest how I can add these 2 columns to the CSV file and
only have the static text on the first row (Note the text has to be on
in the same row as the first row of the table).

Thanks for any help

PC
Make your query a union
Select "" As Col1, "" As Col2, Name, Addr from Test
Union
Select "SA" As Col1, "3357" As Col2, "" As Head1....From Test

Then futz with how you want it ordered so that it floats to the top.
Jul 14 '06 #3
pmc1 wrote:
Thanks for you reply.

This works to a point. The issue I have is that the first row only
contains the static text and each column in the first row there after
is blank. I need the first row of the resulting recordset to contain
both the static text AND the first row of the original table.

Any suggestions

Thanks again.
Sure. When in doubt, create a kludge.
http://dictionary.reference.com/browse/kludge

You'll have to use your imagination on this and adjust it to your needs.

I will assume you are calling this from a form (we'll call it Form1).
On the form, add a new textbox and call it TopID. Make it's visible
property false. Default Value 0 or "0" depending on if the unique id is
char or numeric.

Now create a query that presents the data for export (use the one you
currently have). Call it Query1. You'll need a field that makes this a
UNIQUE row. I use a field called ID which you might not have in it.

Now, in the code do something like this
Dim rst As DAO.Recordset
set rst = Currentdb.OpenRecordset("Query1",dbopensnapshot)
If rst.RecordCount 0 then
rst.MoveFirst
Forms!Form1!TopID = rst!ID
...process for more actions like runninq query2

OK, Now you've assigned the top row's ID from Query1 to the form's variable.

Now create Query2. It will be something like
Select "" As Col1, "" As Col2, Query1.* From QUery1 _
Where ID <Forms!Form1!TopID
UNION
Select "123" As Col1, "456" As Col2, Query1.* From QUery1 _
Where ID = Forms!Form1!TopID

And futz with the sort.

Basically, any records with an ID not equal to the TopID will have blank
columns and they will get unioned to the one record equal to the top one.

There may be better ways to do this but heck, if it works who cares?


Jul 14 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Angel Cat | last post by:
I'm exporting a large file from a large Production database (SQL). Users are currently updating and inserting new records. Does the export take a snapshot of the data when it starts ? or will...
3
by: sridevi | last post by:
Hello How to export data from ms-access database to excel worksheet using ASP. mainly i need to export data to multiple worksheets. it is very urgent to us. i have a sample code which works...
1
by: Jacky11 | last post by:
I have a column name the Data type is MEMO The input is more than thousands of characters. When exporting, not all the information is exported. Who can I correct this problem? Thanks
2
by: Kenneth | last post by:
How do I remove the limitation in Access that deny me from exporting 24000 rows and 17 columns (in a query) into Excel? Kenneth
1
by: Mustufa Baig | last post by:
I have an ASP.NET website where I am showing off crystal reports to users by exporting them to pdf format. Following is the code: ---------------- 1 Private Sub ExportReport() 2 Dim oStream...
2
by: bienwell | last post by:
Hi, I have a question about exporting data from datagrid control into Excel file in ASP.NET. On my Web page, I have a linkbutton "Export data". This link will call a Sub Function to perform...
2
by: Snozz | last post by:
The short of it: If you needed to import a CSV file of a certain structure on a regular basis(say 32 csv files, each to one a table in 32 databases), what would be your first instinct on how to...
0
by: =?Utf-8?B?ZGVuIDIwMDU=?= | last post by:
hi, I trying to export data display on a gridview that supports any language (like chinese, japanese, thai, french) shown here is chinese only. There is no problem exporting english language...
4
by: myemail.an | last post by:
Hi all, I use Access 2007 and have the following problems: when exporting banal select queries (either to Excel or to a csv file) I find that exporting often doesn't work and creates a file with...
1
by: Marty Klunk | last post by:
I have an Access97 data base where we are exporting records out to a text file that is then sent to a customer via EDI transmission. The problem I am having is that during the export process access...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.