Solved

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

Posted on 2016-11-13
2
28 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

747 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

11 Experts available now in Live!

Get 1:1 Help Now