Results 1 to 3 of 3
  1. #1
    itm is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2011
    Posts
    69

    Having troble exporting a text delimited file

    Hi,
    I have an export rutine in my VBA code as follows that works great:
    rs2.MoveFirst 'Moves to the first record

    'This loops through output the dat to text files
    While Not rs2.EOF
    DoCmd.TransferText transfertype:=acExportDelim, _
    specificationname:="Fi707sp", _
    tablename:="TempHd", _
    filename:=fname, _
    hasfieldnames:=True


    rs2.MoveNext
    Wend
    The problem is that when it go through this it depends on the spesification file being the same each time. The columns are dates that a cross tab query creates, and depending on the what the user picks for date selection; there are different columns of dates. But the spesification is based on certing dates for the collumns.
    So how can I do this without the the spesification file. I know there are filescripting methods and free file, but I am not sure (a) how to use these for delimited text files and (b) how to have it go through and grab the number of columns I have at the time. Or if therer is a way to get the DoCmd to work.
    Any ideas would really be appricated.
    Thank you

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Do you have a specification name for every possible permutation of your data? If you do, is it strictly on the number of columns produced by the crosstab query? If it is you could do something like this:

    Code:
    if rst2.fields.count = 10 then
         'set your export specification to item x
    elseif rst2.fields.count = 11 then
         'set your export specification to item y
    elseif
         'and so on
    endif
    I seem to have a memory of crosstabs being very temperamental when you perform an export what I typically do is create a temporary access table then export that table, particularly if you are exporting a crosstab with *ANY* criteria at all. If your crosstab has criteria you may have to create the SQL statement in your code to get it to run without generating an Access table first.

  3. #3
    itm is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2011
    Posts
    69
    The problem is that the number and name of the heding will be different each time. However I solved this by writing a script that sends the file out by file scripting code and in therre I was able to loop through the fields; and this way I did not need a spec. sheet, and it had far better performance.
    Thank you
    itm

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 02-20-2011, 08:22 PM
  2. Exporting to Text File
    By blandow in forum Import/Export Data
    Replies: 2
    Last Post: 08-06-2010, 06:02 PM
  3. Replies: 1
    Last Post: 07-31-2010, 08:04 AM
  4. Exporting data to text file
    By NC_juggler in forum Import/Export Data
    Replies: 0
    Last Post: 11-21-2008, 10:51 AM
  5. Importing a tab delimited file into access table - please he
    By championss in forum Import/Export Data
    Replies: 0
    Last Post: 10-29-2006, 02:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums