• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 287
  • Last Modified:

Export table to a file with *.cth extension

Hey there...is it possible to use the transferspreadsheet, or transfertext command to export a table and specify the extension.
For example, i want to export a table to a file with a *.cth extension.

Is it possible to use this command in way, or should I just go about writing my own routine to write the file?
0
andrewfly
Asked:
andrewfly
  • 3
  • 3
  • 2
1 Solution
 
rockiroadsCommented:
when u use docmd.transferspreadsheet or transfertext, why dont u just specify the filename with your own suffix, that would do it
0
 
rockiroadsCommented:
e.g. DoCmd.TransferText acExportDelim, , "tablename", "c:\myfile.cth", True

does this not do it?

0
 
harfangCommented:
Hello andrewfly

The method you choose will determine the file format. You can of course choose your file name and file extention freely, but this will not affect the file format. So the question is: what format do you require?

(°v°)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
andrewflyAuthor Commented:
hey guys, thanks for the responses...i just missed them at work, when i get back in tomorrow ill give it a whirl first thing. thanks a lot!
0
 
andrewflyAuthor Commented:
id prefer a comma delimited text file...i am exporting a table of data that can later be imported to 'resume' a session in my access program.  i would normally just export it as an excel file, but users like to poke around and modify excel files.  when they see a non-windows native file format they tend to be a little more intimidated and not touch the files :) ...thus, the *.cth extension.

i am using the following code in my export routine (calling the common dialog as you can see)...

''''''''''''''''''''''''''''''''''
MsgBox "Please enter filename to save a Compthml data file for later use.", vbOKOnly

strFilter = ahtAddFilterItem(strFilter, "Compthml project file (*.cth)", "*.cth")
strSaveFileName = ahtCommonFileOpenSave( _
                                    OpenFile:=False, _
                                    Filter:=strFilter, _
                    Flags:=ahtOFN_OVERWRITEPROMPT Or ahtOFN_READONLY) '
DoCmd.TransferText acExportDelim, , "tblCTHExport", strSaveFileName, True
''''''''''''''''''''''''''''''''

It appears that Access needs this to have a *.txt format.  When I change the filter to txt, everything works fine...however, when I leave it like this, I get a 3027 error..Cannot update. Database or object is read only.
However, I know its not, because the .xls and .txt export routines work fine....any ideas?
0
 
harfangCommented:
Hello andrewfly

You are right. It never occured to me that the DoCmd would actually use the file extension for something. This is a little weird, I don't think I see the point.

Anyway, VB is not that ticklish about file extensions, so everything goes:

    strTextFileName = Left(strSaveFileName, InstrRev(strSaveFileName, ".")) & "txt"
    DoCmd.TransferText ...... strTextFileName, True
    Name strTextFileName As strSaveFileName

Cheers!
(°v°)
0
 
harfangCommented:
You might want to delete any previous *.txt or *.cth file...

    Kill strSaveFileName
    Kill strTextFileName

(°v°)
0
 
andrewflyAuthor Commented:
perfect, thanks again
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now