Solved

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

Posted on 2016-11-13
2
59 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 20

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

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…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
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, when working with VBA, learn some techniques for writing readable and easily maintained code.

737 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