?
Solved

How do I adjust excel column widths when exporting from Access with DoCmd.OutputTo

Posted on 2008-10-12
2
Medium Priority
?
414 Views
Last Modified: 2013-11-27
Hi I am using the following code to export an excel spreadsheet from Access.

DoCmd.OutputTo acOutputQuery, "qry_export", acFormatXLS, rs!state_FK & "-" & rs!Declaration & " Loan Closing " & DatePart("m", dteReport) & "-" & DatePart("d", dteReport) & "-" & DatePart("yyyy", dteReport) & " .xls"

What vba code do I use to make the second column ("B") export with the autofit option so the cell contents aren't truncated?
0
Comment
Question by:BradleyOnTheRoad
[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 93

Accepted Solution

by:
Patrick Matthews earned 2000 total points
ID: 22699686
Since you need to automate Excel to do the column width, I'd just do this:

Dim xlApp As Object, xlWb As Object
Dim rsOut As DAO.Recordset

Set xlApp = CreateObject("Excel.Application")
Set xlWb = xlApp.Workbooks.Add
With xlWb
    Set rsOut = CurrentDb.OpenRecordset("qry_export")
    With .Worksheets(1)
        .[a1].CopyFromRecordset rsOut
        .Columns(2).AutoFit
    End With
    .SaveAs rs!state_FK & "-" & rs!Declaration & " Loan Closing " & Format(dteReport, "yyyy-mm-dd") & ".xls"
    .Close False
End With

Set xlWb = Nothing
xlApp.Quit
Set xlApp = Nothing
0
 

Author Closing Comment

by:BradleyOnTheRoad
ID: 31505514
Thanks. That'll do the trick.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

719 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