Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    dev82 is offline Novice
    Windows XP Access 2002
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    9

    Question Export query to Excel

    Hey Folks,



    i have a problem with my query export to excel. my code is:

    Code:
    Private Sub Befehl1_Click() 
        DoCmd.TransferSpreadsheet acExport, 8, "Umsatz_Netto", "C:\Abfrage.xls" _ 
                                , True, "Umsatz_Netto" 
    End Sub
    i set the format for numbers in the query to: #.##0;(#.##0)
    but access does not get the right format the excel sheet is wrong. the format is not correct.

    dou you have any ideas? how could i write the vba code?

    thanks
    Dev82

  2. #2
    thhui is offline Competent Performer
    Windows XP Access 2002
    Join Date
    Feb 2009
    Posts
    235
    The other way round is pulling the raw data from access and then
    setting it as you want in excel by using vba in excel instead.

  3. #3
    dev82 is offline Novice
    Windows XP Access 2002
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    9
    Hello,

    thanks for your answer. is there no other way to do that?

    regards
    Dev82

  4. #4
    NTC is offline VIP
    Windows Vista Access 2007
    Join Date
    Nov 2009
    Posts
    2,392
    in the access table field definition - increase the decimal count. also be sure this parameter is consistent in any form controls for this field also.

    you want that 0 value held in the table itself, not tagged on at the last minute via vb.

  5. #5
    dev82 is offline Novice
    Windows XP Access 2002
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    9
    hello,

    i have an photo from my query there is the right format.


  6. #6
    Rawb is offline Expert
    Windows XP Access 2000
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    If the Query doesn't export with the proper formats, the only option I can think of is to use Office Automation.

    Export the Query like normal. Then use Office Automation to open the Excel Spreadsheet and correct the format for the columns that are wrong.

  7. #7
    thhui is offline Competent Performer
    Windows XP Access 2002
    Join Date
    Feb 2009
    Posts
    235
    You can call excel vba in Access.
    But knowing excel vba is critical.

  8. #8
    thhui is offline Competent Performer
    Windows XP Access 2002
    Join Date
    Feb 2009
    Posts
    235
    Excel automatically overrides the format access gives out.
    You can test this with simple csv file with value 0 in 0.000 format
    Last edited by thhui; 02-09-2011 at 09:45 AM.

  9. #9
    Rawb is offline Expert
    Windows XP Access 2000
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    Ummm. So it turns out we're all wrong. . .

    The problem's in your format, not in the Query: You need to use "#.000;(#.000)" instead of "#.##0;(#.##0)".

    In "#.##0;(#.##0)", you're telling Excel that it only needs to show the third digit after the decimal (12.100 will show 12.10 because the first 0 after the decimal is hidden)!

  10. #10
    thhui is offline Competent Performer
    Windows XP Access 2002
    Join Date
    Feb 2009
    Posts
    235
    It stuns me after my trial in actual operation in my access.

    Format under the query like "#,##0.000" works after the export to excel button is pressed.

    Only csv and text files failed.

    The format could be retained in the export to excel operation.

  11. #11
    Rawb is offline Expert
    Windows XP Access 2000
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    lol!

    I actually ran into the opposite: I created a Query in Access (and specified formats for the result Fields). Then, when I exported it to Excel, it ignored my Query format settings. It did, however, use the Table format settings!

    To get around this, I had to use OLE Automation (Office Automation). To see exactly what I did, check out the attached Access Database (the VBA code is in Form1)

  12. #12
    thhui is offline Competent Performer
    Windows XP Access 2002
    Join Date
    Feb 2009
    Posts
    235
    Dear Rawb,

    Your access file has some interesting features:-
    Not allow me to open - saying it is excluded from safe domain and must obtain my approval of protection to open it.

    Also, upon opening the query, I cannot find the windows interface to have the option to change format.
    I make a new query and format it accordingly and
    find it is proper to export the data with format changed in the query window.

    For the original table, I export it with the format option properly displayed in excel either.

    I see your form and vba code.
    It is using excel vba to format the data after the export.
    The same approach like me stated before.

  13. #13
    dev82 is offline Novice
    Windows XP Access 2002
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    9
    @ thhui,

    thats right, there is something wrong with this access file, i cant open it.

  14. #14
    thhui is offline Competent Performer
    Windows XP Access 2002
    Join Date
    Feb 2009
    Posts
    235
    Just right click the mdb file and there is option for properties that can force to open it by eliminating the protection.

  15. #15
    dev82 is offline Novice
    Windows XP Access 2002
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    9
    Hello thhui,

    thanks for the info. but the format in the sheet is wrong. as you already written in your previous message.

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

Similar Threads

  1. Export to excel different sheets
    By apsf68 in forum Access
    Replies: 2
    Last Post: 07-27-2010, 07:05 AM
  2. Access export to Excel
    By Rick West in forum Import/Export Data
    Replies: 4
    Last Post: 01-09-2010, 03:40 PM
  3. Export Query to Various Excel Files
    By dalet in forum Import/Export Data
    Replies: 7
    Last Post: 11-09-2009, 09:22 AM
  4. Export a simple query result to an excel file
    By wop_nuno in forum Import/Export Data
    Replies: 1
    Last Post: 05-21-2009, 04:18 AM
  5. Export to Excel
    By vaikz in forum Import/Export Data
    Replies: 3
    Last Post: 03-25-2009, 09:37 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