Solved

Creating an xls in Access 2010 VBA not working

Posted on 2014-11-30
6
174 Views
Last Modified: 2014-12-01
Hey Everyone,  

I have an Access 2010 program that at one point allows the user to create an excel export file from the data (well originally I had the program creating a csv file).  Someone is helping me update this program so it works cleaner and in conjunction with the cloud so they changed the code slightly.  Now I get an error box that says "The format in which you are attempting to output the current object is not available"

Here is the original code that worked:

  DoCmd.TransferText acExportDelim, "", "Export Plan Selection and Deduction To Send Sorted", "\\HOST33\ShareFile\CLIENTS\3CTRPS\Export for " & UCase(txtClientID.Value) & " Date-" & Replace(CStr(Date), "/", "-") & " Time-" & Replace(CStr(Time), ":", "-") & ".csv", True, ""

Here is the code that he created:

DoCmd.OutputTo acOutputReport, stdocname, acFormatXLSX, strFilename

(the variables produce the same name for the file as the first one does).

I tried changing it to read acFormatXLS also and it still did not work.

Any help is really appreciated!
0
Comment
Question by:alevin16
6 Comments
 
LVL 24

Expert Comment

by:chaau
ID: 40473011
Do you have MS Excel installed on the machine you run the code? The code will only work if you have Excel installed.
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 40473359
> Here is the code that he created:

Then why not address "he" your issue?

Anyway, run this:

    DoCmd.OutputTo acOutputReport, stdocname

and you'll be listed/prompted for the possible output formats.

/gustav
0
 
LVL 48

Accepted Solution

by:
Rgonzo1971 earned 200 total points
ID: 40473574
Hi,

Maybe try to change the suffix of your file to xls

Regards
0
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.

 
LVL 31

Assisted Solution

by:Helen_Feddema
Helen_Feddema earned 300 total points
ID: 40473785
For the TransferSpreadsheet method, when creating an .xls workbook, use the acSpreadsheetTypeExcel9 named constant for the spreadsheettype argument:

   strQuery = "qryDataForExport"
   strDBPath = Application.CurrentProject.Path
   strFileName = "Exported Data.xls"
   strFilePath = strDBPath & "\" & strFileName
   Debug.Print "File with path: " & strFilePath
   DoCmd.TransferSpreadsheet transfertype:=acExport, _
      spreadsheettype:=acSpreadsheetTypeExcel9, _
      tablename:=strQuery, _
      FileName:=strFilePath, _
      hasfieldnames:=True

Open in new window


For Office 2010, use the acSpreadsheetTypeExcel12Xml argument and the .xlsx extension for the filename

DoCmd.TransferSpreadsheet transfertype:=acExport, _
   spreadsheettype:=acSpreadsheetTypeExcel12Xml , _
   tablename:="qryCustomers", _
   FileName:=strWorkbook, _
   hasfieldnames:=True

Open in new window

0
 

Author Comment

by:alevin16
ID: 40473897
Thanks to all, I tried the xls and it seemed to work for now but I think I will try the last suggestion also.
0
 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 40473945
It just depends on what type of workbook you want to create -- both should work.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

706 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

18 Experts available now in Live!

Get 1:1 Help Now