Solved

How to format Query so resulting excel file is properly formatted.

Posted on 2016-11-13
2
38 Views
Last Modified: 2016-11-17
SO I have a  Query that is used to export a spreadsheet however the columns are not properly formatted causing the user to resize the column manually.  Anything that can be done??

I have attached the output that my program creates.
myexcel.xlsx
0
Comment
Question by:seamus9909
2 Comments
 
LVL 19

Accepted Solution

by:
crystal (strive4peace) - Microsoft MVP, Access earned 500 total points
ID: 41885578
When you use TransferSpreadhseet, you do not have the opportunity to manipulate the workbook.  Alternately, you could use code to transfer what you have.  Here is an example that uses CopyFromRecordset and then formats the worksheet when it is done:

http://www.rogersaccesslibrary.com/forum/document-calculated-fields-in-queries_topic619.html
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 41885581
The only way I have done this is to use Excel Automation to open Excel, create a new workbook, paste the query as a recordset into the spreadsheet starting at cell A2 using the CopyFromRecordset method.  Then loop through the recordset fields and take the field caption or Name and paste that into the cells starting at A1.

Then, after that, move from column to column and format the columns using the columns NumberFormat property to set the correct format for each of the columns.  You can also use the columns Autofit property to automatically size each column to fit all text, or can use the ColumnWidth property to manually set the column width.  And, if you need it, you can use the Columns WrapText property to wrap the text in columns that are wider than a specific width.

This method is the only way I have ever been able to ensure that the spreadsheet columns will be in the right format and width.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now