?
Solved

Creating an xls in Access 2010 VBA not working

Posted on 2014-11-30
6
Medium Priority
?
200 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
[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
6 Comments
 
LVL 25

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 51

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 52

Accepted Solution

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

Maybe try to change the suffix of your file to xls

Regards
0
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 
LVL 31

Assisted Solution

by:Helen Feddema
Helen Feddema earned 1200 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
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 …
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

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