Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

user interface for export data to csv 2

Status
Not open for further replies.

Pampers

Technical User
Joined
Apr 7, 2004
Messages
1,300
Location
AN
Hi everyone,
I have button on my form that exports the content of a query to a file. There are two things I want to alter:
1. I want the users to be able to use MS Explorer to save the file - instead of the input messagebox (see code below)
2. I want the output to be csv
but I don't know how...

Code:
Private Sub Command47_Click()
Dim Message, Title, Default, MyValue
Message = "Enter a FileName"    ' Set prompt.
Title = "EDI Messagebox"    ' Set title.
Default = "C:\Documents and Settings\alaerds\My Documents\FileName.txt"    ' Set default.
'Display message, title, and default value.
MyValue = InputBox(Message, Title, Default)

DoCmd.TransferText acExportDelim, , _
    "qryContainerMovesEDI", MyValue


Pampers [afro]
You never too young to learn
 
check out this site:
it uses the windows api to do file stuff. works a charm, even though i can proudly say i don't understand it all.
i am not sure on the transfer text, i use it for fixed width... but i'll see if i can find anything.
 
acExportDelim, which you have, should give a CSV file. Is it not working out for you?

A search for File Dialog may give you options in addition to the above, depending on your version of Access.

 
To export to CSV, an export spec must be established. I do this by selecting on the query, right mouse click and select export. You have to use the advanced button to first create the spec and then to save it with a name. Then in your transfertext command be sure to add the spec name to get the desired results.
 
stix4t2
I find that in Access 2000, I do not need an export specifcation to create a CSV, acExportDelim works. Perhaps this is a version thing?
 
Tnx all for the help.
Remou: it works, but I dont want that the exported textfields are enclosed with "" - is that possible?

spizotfl: I will put the code, and see how it works. I'll be back with the result

Pampers [afro]
You never too young to learn
 
In that case you _do_ need an export specification, as stix4t2 has suggested. Quotes ("") are the standard for CSV, but you can do non-standard exports with a specification.
 
... But be careful of text fields that contain commas, because it will throw your export file out: 21, The Street will become two fields. That is why text is usually quoted.
 
Hi spizotfl and others,
I went to Lebans instead, and imported his module as instead pasting the code. (Lebans code is corrected for A2K or higher, at: Works like charm.

And by setting the following line of code to 'false' in the on-click() of the button, you get a Save File Dialog Box instead of the Open File Dialog Box.
Code:
Filter:=strFilter, OpenFile:=False,

Remou and Stix4t2: i will have a closer look on how to create and use an 'export spec'. Keep you posted.


Pampers [afro]
You never too young to learn
 
Wow,
I created an export spec, saved it, used in the Transfertext method and... it works great. I could create the output just the way I wanted - or rather: the way the receiving company wants it (delimited by a space, no quotes). Big smile here. Tnx a lot Remou and stix4t2. Have a good weekend; here on our island, the crazy carnaval just started, so... I'll drink to you guys.

Pampers [afro]
You never too young to learn
 
Hi guys,
Back again on this issue. All is ok, except for one small thing. If I give an export-file name a file extension other than csv, txt (and tab, asc), it gives the error message "Run time error 3027. Cannot update. Database or object is read only."

Is there a way around this so I can give for example the export file a .dat file extension? (Of course I can allways change the file extension afterwards, but I rather have it in one go ;-)



Pampers [afro]
There is only one way to change a diaper - fast
 
This:
Importing text files with non-standard file extensions.
thread181-1203735
Is to do with import, but may be relevant to export, I haven't tried the change to the registry. [dazed]
 
Hi Remou,
Sorry, I missed your last post. Excellent reference! Changing the registry, by adding the desired extension (aka .dat), makes it possible to save (and import) files with a .dat-extensions. My registry for DisabledExtensions now holds:

!txt,csv,tab,asc,tmp,htm,html,dat



Pampers [afro]
There is only one way to change a diaper - fast
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top