Page 1 of 2 12 LastLast
Results 1 to 15 of 25
  1. #1
    jgelpi16 is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544

    Question File Export "sort" issues

    I have the below code that runs to export a text file. I have both the Pgarn01 query and the table set to Ascending order by ID. However, when the export occurs a strange thing happens. The data will display as

    header record
    record 5
    record 6
    record 7
    record 8
    footer record
    record 1


    record 2
    record 3
    record 4

    The expected result (and how it is displayed in both the query and table) is:
    header record
    record 1
    record 2
    record 3
    record 4
    record 5
    record 6
    record 7
    record 8
    footer record

    The header record has "000000000" as the value in the ID field and the footer record has "999999999" as the ID field value.

    What is going on?

    Code:
    Private Sub cmdExportPgarn_Click()
    Dim varHeaderNme As String
    Dim varHeaderSSN As String
    Dim varQueryName As String
    Dim varSpecName As String
    Dim varTableName As String
    Dim varFileName As String
    Dim varTextFile As String
    Dim varHeaderDate
    Dim varBankName As String
    Dim varBankCode As String
    Dim varNewFolder As String
    Dim varFileRename As String
    varBankCode = cboBankName.Column(2)
    varBankName = cboBankName.Column(1)
    '**********pgarn.txt
    varHeaderNme = "***From: NCDOR; To: " & varBankName & "; pgarn" & varBankCode & ".txt***"
    varHeaderSSN = "000000000"
    varHeaderDate = Format(Date, "MM/DD/YYYY")
    DoCmd.SetWarnings False
    varQueryName = "Pgarn00"
    DoCmd.OpenQuery varQueryName, acViewNormal
    mySQL = "INSERT INTO AAtblBankExport (EntityID, FullName, GarnDate) VALUES ('" & varHeaderSSN & "', '" & varHeaderNme & "', #" & varHeaderDate & "#)"
    CurrentDb.Execute mySQL, dbFailOnError
    varQueryName = "Pgarn01"
    DoCmd.OpenQuery varQueryName, acViewNormal
    varQueryName = "PGarnFooter"
    DoCmd.OpenQuery varQueryName, acViewNormal
    DoCmd.SetWarnings True
    varSpecName = "AAtblBankExport Export Specification"
    varTextFile = "pgarn" & varBankCode & ".txt"
    varFileRename = "pgarn" & varBankCode
    varTableName = "AAtblBankExport"
    varNewFolder = "C:\File\Archive\" & varFileRename & Format(Date, "MMDDYYYY") & ".txt"
    varFileName = "C:\File\" & varTextFile
    Name varFileName As varNewFolder
    DoCmd.TransferText acExportFixed, varSpecName, varTableName, varFileName
    End Sub

  2. #2
    NTC is offline VIP
    Windows Vista Access 2007
    Join Date
    Nov 2009
    Posts
    2,392
    hmmm well off the cuff, does the export spec have the ability to do OrderBy ? I honestly can't remember. you would want to look into that.

    only the table and the export line of the code count here - everything else is prelude.

    you mention an ID field that is being used to sort the exported table correctly. does that ID field also get exported? if not - you might try an experiment in having the table sorted correct but without that ID field existing. rewrite it to a new table without that field. don't mean to send you on a wild goose chase but it might give you some insight....

    is a little odd; one could do a post process text rearrange in vb but one would want to avoid that....

    also as a sanity check I might just make a new export spec for that table - and run it manually to see what happens. have done plenty of these and have never had an order problem - but on the other hand the order often doesn't matter so maybe I didn't inspect it closely. thinking back on one project that involved a header/footer I recollect that I exported those all as separate files (header, body, footer) and then glued them together using vb...but that was needed for coincidental reasons as I couldn't get them all into one record set.

    hope this helps a little.

  3. #3
    jgelpi16 is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    Thanks for the help. I don't see a sort in the import spec. The ID field is being export to the text file. I guess to me the perplexing thing is the data shows up just fine in the table and query. It is not until I export the data that it gets messed up. Have you hever heard of this issue pertaining to network drives? I am exporting to a network drive so maybe there is a network interruption that is causing this? It hasn't done it in a while now so maybe it was just a fluke? Thanks for the help.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Don't export a table. Export a query with an OrderBy clause!

  5. #5
    jgelpi16 is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    Ok, that will work with one exception.....I need to OrderBy FileCode and then by ID.

    i.e.....

    ID FileCode
    1 a
    2 a
    3 a
    4 a
    1 b
    2 b
    3 b
    4 b

    This may be simple but I can't get it to work.

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    OrderBy FileCode; ID

  7. #7
    jgelpi16 is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    Thank you!...One problem. When I do that I get an error message stating "Characters after end of SQL statement" or something like that.

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Is this thread ready for you to follow the link in my sig and mark as Solved?

  9. #9
    jgelpi16 is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    Not quite yet....

  10. #10
    jgelpi16 is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    When I use the Query Builder, or whatever you want to call it, and then look at the SQL it has it as follows:

    Code:
    ORDER BY FileCode, ID;

  11. #11
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Oops, my bad. comma then semicolon.

  12. #12
    jgelpi16 is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    That does not work. When I run that it orders it entirely by FileCode and disregards the ID sort.

  13. #13
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Sorry but I have to leave for several hours. You are saying it does not sort correctly just looking at the Datasheet mode of the query? Is your OS and Office up to date on patches?

  14. #14
    jgelpi16 is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    I am operating Office 2007. All patches, etc are up to date. When I look in Datasheet mode it sorts based upon FileCode and does not sort by ID. Thanks for your help.

  15. #15
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Are you talking about the Datasheet view of the Query or the Table? Can you post the SQL for the Query so we can see it please?

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 04-10-2010, 10:22 AM
  2. Replies: 1
    Last Post: 04-07-2010, 08:49 AM
  3. Can I pass "sort by" using DoCmd.OpenReport
    By alsoto in forum Reports
    Replies: 3
    Last Post: 04-16-2009, 08:11 PM
  4. Replies: 0
    Last Post: 03-26-2007, 02:12 AM
  5. Export to .rtf of "104-" converts to "-655&qu
    By Sherri726 in forum Import/Export Data
    Replies: 0
    Last Post: 12-19-2006, 03:16 PM

Tags for this Thread

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