Consulting

Results 1 to 4 of 4

Thread: Access to Excel transferspreadsheet and automatic sort data

  1. #1
    VBAX Regular
    Joined
    Jan 2007
    Posts
    42
    Location

    Access to Excel transferspreadsheet and automatic sort data

    Hi, im puzzeled.

    I have an access data base that has two colums of data, a driver name in the first column and an ID number in the second column.

    in access, I do a data sort by ID number and then, when I run the following code it dumps this data in excel, but its not sorted in the same order as in excel.

    My objective is to have this data automatically sorted in excel without having to do anything in excel... ie.. I want the sorted version in Access to be dumped in excel, exactly as it appears in Access...

    the code i have running in access is as follows

    [VBA]

    Option Compare Database
    Function modTransfer()
    On Error GoTo modTransfer_Err
    'docmd.TransferSpreadsheet TransferType, Version, TableName, _
    'FileName, HasFieldNames(True/False), Range
    DoCmd.TransferSpreadsheet acExport, 8, "MASTER", _
    "H:\Cash reconciliation progressive backup\clarks driver database migration\Driver Database.xls", True, ""

    modTransfer_Exit:
    Exit Function
    modTransfer_Err:
    MsgBox Error$
    Resume modTransfer_Exit
    End Function



    [/VBA]


    What do I do and how do i do it??

  2. #2
    Moderator VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    Is "MASTER" the table? If so, you'd probably be better off creating a query that sorts the records by ID, and export the query rather than the table.

  3. #3
    VBAX Regular
    Joined
    Jan 2007
    Posts
    42
    Location

    query export...

    HI there.. I already tried to export a query to excel but how do you do this in code...

    btw, master is the tabel name

    I created a query named QRY_MASTER

    then wrote the code:

    [VBA]


    Option Compare Database
    Function modTransfer()
    On Error Goto modTransfer_Err
    DoCmd.TransferSpreadsheet acExport, 8, "QRY_MASTER", _
    "H:\Cash reconciliation progressive backup\clarks driver database migration\Driver Database.xls", True, ""

    modTransfer_Exit:
    Exit Function
    modTransfer_Err:
    MsgBox Error$
    Resume modTransfer_Exit
    End Function
    [/VBA]


    but this doesnt work... how can i fix this all in code.. so i can export the results of a query to excel.... thankyou sooo much

  4. #4
    Moderator VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    That looks correct, although you don't need anything after TRUE in your TransferSpreadsheet statement.

    What is the error that you're receiving?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •