Solved

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

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

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 48

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

691 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