473,763 Members | 6,401 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Export MS Access Query to CSV File

12 New Member
Hello, I'm having some troubles exporting a query to a csv file. I am able to use the doCMD.TransferT ext to output the query to the csv file, however, I cannot get it to use the Export Specifications and on some queries data is showing up in what looks like HEX. Below is an example:

SQL Statement for Invoice_Header Query:
Expand|Select|Wrap|Line Numbers
  1. SELECT [Forms]![Form1]![Invoice_ID] AS inv_id, [Forms]![Form1]![Trans_Date] AS tran_date, Sum(Item_Lot_Query.total_gross) AS total_gross
  2. FROM Item_Lot_Query;
The SQL statement for the query Item_Lot_Query is:
Expand|Select|Wrap|Line Numbers
  1. SELECT Invoice_Raw_Data.Trans_Date, Invoice_Raw_Data.Item_Num, Mid$([Invoice_Raw_Data]![Item_Num],6,7) AS gpitem, GL_Codes.[gl dsitribution], Invoice_Raw_Data.Lot_Code, Invoice_Raw_Data.Shipped_Qty, IIf([Invoice_Raw_Data]![Tot_Gross Amt]=0,0.01,[Invoice_Raw_Data]![Tot_Gross Amt]) AS total_gross, Invoice_Raw_Data.[Order_Type Code]
  2. FROM GL_Codes INNER JOIN Invoice_Raw_Data ON GL_Codes.Item = Invoice_Raw_Data.Item_Num
  3. WHERE (((Invoice_Raw_Data.[Order_Type Code])<>"INTL") AND ((Invoice_Raw_Data.Charge_To)<>"") AND ((Invoice_Raw_Data.[Reason Code])="SALE"))
  4. ORDER BY Mid$([Invoice_Raw_Data]![Item_Num],6,7), Invoice_Raw_Data.Lot_Code;
Invoice_Raw_Dat a is a table linked to a CSV file that I get from a vendor. The ultimate goal of this access db is to get the data into a format that can be accepted by another system.

When I run the queries with the From1 open and data entered, I get tables just how I want them.

When I run the following VB code I get the CSV file below
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command11_Click()
  2. On Error GoTo Err_Command11_Click
  3.  
  4.     Dim stExpName1 As String
  5.     Dim strFile1 As String
  6.  
  7.     stExpName1 = "Invoice_Header_Query"
  8.     strFile1 = "d:\GP_Project\Output\Invoice_header.csv"
  9.     strExportSpec1 = "Export1"
  10.  
  11.     DoCmd.TransferText acExportDelim, TableName:=stExpName1, FileName:=strFile1, HasFieldNames:=True
  12.  
  13. Exit_Command11_Click:
  14.     Exit Sub
  15.  
  16. Err_Command11_Click:
  17.     MsgBox Err.Description
  18.     Resume Exit_Command11_Click
  19.  
  20. End Sub
The From that is referenced is open when the command is run with the following information:
Inv_ID is Jun_08
Trans_date is 6/30/2008

The CSV file looks like this:
"inv_id","tran_ date","total_gr oss"
4A 00 75 00 6E 00 5F 00 30 00 38 00 ,00 00 00 00 A0 59 E3 40 ,18129108.99

It should look like:
"inv_id","tran_ date","total_gr oss'
"Jun_08","tran_ date",18129108. 99


My first question is: Why are my two parameters showing up in HEX(?) format? And how do I stop it.

Second question is, I want to set the text quallifier as {none} as can be done in the advanced export settings box. I did this and saved an export specification as Export1. When I run my export command with Export1 as the specification, I get an error:
"The data being exported does not match the format described in the Schema.ini file." I've read about this file a little bit in Microsofts KB, but I can't find it on my computer anywhere.

I would greatly appreciate any help with these problems.

Chad
Sep 22 '08
17 19910
NeoPa
32,572 Recognized Expert Moderator MVP
Is the form open when you run the Export?

I guess it must be but can you confirm.
Oct 3 '08 #11
chadh
12 New Member
Yes, that's the strange thing. The form is open with data entered. When I run the query and get a data table (with the parameters showing as expected), so the references to the form must be correct. My only guess is perhaps this is a bug in Access. I'm running Access 2003 SP3.

Chad
Oct 6 '08 #12
NeoPa
32,572 Recognized Expert Moderator MVP
If you use the form values as selection criteria then I doubt you would have a problem. Can you confirm you are trying to export a value which comes from the form?

As this would leave the data type undefined I can see why the wizard might have a problem with it. If this is the problem we can look at ways of getting around it.
Oct 7 '08 #13
chadh
12 New Member
I have some new information. In the query, I wrapped the parameters inside the cstr() function and they exported as text and not the unicode, which in fact was binary. The purpose of these form values is not selection criteria. I need a way of putting user-defined text with each record. The original data set is a linked table that will change frequently. This information is not included in the data set, it is the same for each record. For example, the data reflects invoice line items for an entire month. It is being compiled and will be entered in bulk into MS Great plains which will treat the import as one large invoice. The user is to supply an invoice id that needs to be in each imported record. My limited Access knowledge lead me to putting these values into the query as parameters. If there is a better way to do this, I'm all for it.

I have not tried manually exporting the query after adding the cstr() functions. Ran out of time last night.

Chad
Oct 7 '08 #14
NeoPa
32,572 Recognized Expert Moderator MVP
If the form control values are actual values to export, then it is probably only the Wizard part which has a problem with it.

Try it with values which are already defined and see if you can get the wizard to complete. Remember, it is only setting up the saved Export Spec that you need the wizard for. Once that has been prepared you can then try it in code with the form control values again.
Oct 7 '08 #15
chadh
12 New Member
Just wanted to let you know the problem has been resolved. I hard-coded values into the queries and was able to export them using the wizard and create the Export Specs. That combined with using the cstr() on the form values. Has given me exactly what I want.

No I just need to figure out how to make line numbers on two of the queries. But I'll start another thread for that one.

Thanks again for your help,
Chad
Oct 8 '08 #16
NeoPa
32,572 Recognized Expert Moderator MVP
No worries. Pop a link in here when you've done it and I'll have a look for you.

I expect you'll be disappointed though. SQL doesn't do relative records I'm afraid.
Oct 8 '08 #17

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

Similar topics

9
6775
by: M O J O | last post by:
Hi, (I'm new to XML) I can export data from Access as an XML file (with schema integrated in the XML file). I can read it into a DotNet DataSet, but the schema is not correct that is - I do not get the right columns. Is there some kinda trick to convert the XML to a DotNet-DataSet-readbable file??
6
33831
by: Oliver Stratmann | last post by:
Hello all, is there another way to export data to a csv-file (comma-separated format)? We tried the EXPORT-command and got the following error " SQL1325N The remote database environment does not support the command or one of the command options. Explanation: An attempt has been made to issue a DB2 workstation database specific command or command option against a host database through DB2
7
5144
by: Keon | last post by:
Hoi, I'm using a database with alot of records in 1 table (more than 3000). If i want to export this table to excel i only get it till record 2385. Do someone know how i can solve this probleme? To export my tables i use folowing code: StTotaal = stLocatieName & "\Archief\" & Year(Date) & Month(Date) & Day(Date) & "_Gegevens.xls" 'location and name where the table must be saved
2
2569
by: GAVO-UK | last post by:
Using Ms Access 2003 I am trying to export a query to a delimited txt file containing some CURRENCY fields, which I want to export without the currently symbol and with five decimals. I have tried everything to get the currency fields with the format I want after exporting but!! NO LUCK!!! This is what I have tried. In the source table the fields are formatted with a DataType=
5
31923
by: Simon | last post by:
Dear reader, With the export command you can export a query to Excel. By activate this command a form pop's up with the following text:
1
10502
by: CoolFactor | last post by:
MY CODE IS NEAR THE BOTTOM I want to export this Access query into Excel using a command button on an Access form in the following way I describe below. Below you will find the simple query I am trying to export to Excel using a command in an Access Form. RowID strFY AccountID CostElementWBS 1 2008 1 7 2 2008 1 7 I want to...
1
4968
by: cut123 | last post by:
I have a query that I would like to export to different Excel documents based on the product. For each type of product I want all pertinent data to export to a different Excel document. There will be over 65,000 rows of data so I can't export it to Excel and break it out in Excel. I would rather not create a separate query for each one, any suggestions? Thanks for your help cut123
15
4085
by: jim | last post by:
Hi All, I need to export a query to a text file but i need each field delimited by a new line. Cant seem to find a way to do it. any ideas.. thanks jim
2
5334
by: ezra | last post by:
I have an access report based on a bunch of queries that does a quarterly summary of some research related stats. Now my boss wants this report to export into excel based on a specific format she has developed. This formatted excel sheet also needs to keep all previous quarters information stored in it and just add subsequent quarters. I don't know where to start!
2
2741
by: Amin Bardai | last post by:
How about this: I want to export results of an MS-Access query into an existing XLS template using TransferSpreadsheet method? I can create a new XLS file but I just want to append records from my query into an existing XLS template.
0
9563
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10144
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9997
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7366
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3522
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2793
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.