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

Can this be done in Access???

Via ODBC I have connected to a MySQL database. I need to extract data into a
csv-file, in such a way that there will be one line with order header info,
one or more ordrelines, one header, one or more order lines, etc. The
content of the "Hedader" and "Line" lines are different.

Can this be done in MS-Access? If not I would appreciate advise on what kind
of tool that could do this job.

John
Nov 13 '05 #1
1 1093
Yes. Using DAO objects this code will do the trick. Say you have a
data table with 3 fields (DAO starts enumerating at 0, so 3 fields would
be 0, 1, 2)

Sub xyz()
Dim DB as DAO.Database, rs As DAO.Recordset
Set DB = CurrentDB
Set RS = DB.OpenRecordset("yourDataTable")
Open "C:\yourCSV.csv" For Output As #1
Print #1, rs(0).Name & "," & rs(1) & "," & rs(2)
Do While Not rs.EOF
Print #1, rs(0) & "," & rs(1) & "," & rs(2)
rs.MoveNext
Loop
Close #1
rs.Close
End Sub

rs is a recordset object based on your data table. I delimit each field
in the recordset object with a comma (thus a cvs file is created with 3
columns) using ",". The first Print #1 prints the column Names on the
first row of the csv file. The next print #1 statement will print each
row of data in your table for each rs.MoveNext. There is more
information in the Access Help Files on the "Open" keyword, and "Output"
and "Print". Note: "Print" does not refer to printing to a printer in
the Access Help files. It refers to printing to a text file (or csv
file, same thing). You can also use the Write method, but that includes
double quotes separating each column and doesn't delimit each
column/field like Print. Write will write each line out like one
continuous string (with the delimiter included - except not delimited
like Print).

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #2

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

Similar topics

0
by: itsharkopath | last post by:
Hi, Imagine a user in a hotspot, when he comes to the hotspot and tries to load a webpage (on the internet), he would automatically redirected to login page. I believe the following is to be...
4
by: Kathleen Turner | last post by:
I have an Excel file that has list of serial numbers followed by a 4 digit code. I have an Access database that has the serial numbers but the field for the 4 digit code is either blank, has the 4...
2
by: Mike MacSween | last post by:
I'm looking at setting myself up as a limited company as far as development work goes. Mainly to insulate my private estate from any business risk. I'd probably just buy an off the shelf company...
4
by: sparks | last post by:
We have a database that reads in and formats raw data. We were using queries to format the data per person and outputing reports. The other database has the persons personal information. I changed...
19
by: davegb | last post by:
Have been trying, in my spare time, to create an Access db for the employees in my group for over a month. It surprised me when I read in the Access Bible that a relationship between the Primary...
3
by: John Bailey | last post by:
When I first built a few web pages in ASP .Net 2.0, I thought it was great. The formview and detailview contorls would automatically layout the controls for you, the update methods were...
1
by: Clay Watson | last post by:
I really need to compute elapsed time using Access and VBA. I have two date/time Access table fields, one for Start and one for Finish. I am trying to calculate net workday work hours. If a...
5
by: darnnews | last post by:
Hi, I have been creating a database to keep track of press clippings, but I have hit a couple stumbling blocks. Any help is much appreciate. 1) Seeing if my query is done I have the...
6
by: Roger | last post by:
if I make a copy of northwind.mdb sample and import data till it reaches 350Gb in size and then I make a second copy of northwind then I open nw1.mdb and do a compact / repair that takes 30-60...
3
by: EGBOK | last post by:
I have spent nearly a year creating a database to track project progress. The database has gone live and everybody is impressed with it. Never contemplated that this would cause so many attention. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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
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:
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...

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.