Solved

Creating an xls in Access 2010 VBA not working

Posted on 2014-11-30
6
190 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 50

Accepted Solution

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

Maybe try to change the suffix of your file to xls

Regards
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
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…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
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…

830 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