3160 Error Exporting to Excel

C

crossb

Hi everyone,

I am using Office 2003 (Access and Excel). In Access, when I try to
use the docmd.transferspreadsheet saving it to an xsl file that already
exists I get the error msg 3160 - Too many fields defined. If I choose
to use a new file name for the export it works fine, no errors. What
can I do to fix this? I don't have this problem on my other computer
that is running Access 2000. Hope my code is readable and not too
unformated when I pasted it in. This is the code I am using:

Private Sub cmdExport_Click()
On Error GoTo ERR_Export
Dim strFilter As String, strInputFileName As String
Dim xl As Object

If lstView.ListItems.count = 0 Then
MsgBox "You must run the report first"
Else
strFilter = ahtAddFilterItem(strFilter, "Microsoft Excel Files
(*.xls)", "*.xls")
strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)",
"*.*")
strInputFileName =
ahtCommonFileOpenSave(Flags:=ahtOFN_OVERWRITEPROMPT Or ahtOFN_READONLY,
InitialDir:=CurrentProject.Path, _
Filter:=strFilter, OpenFile:=False,
DialogTitle:="Save As")
If strInputFileName <> "" And IsNull(strInputFileName) = False
Then
DoCmd.TransferSpreadsheet acExport,
acSpreadsheetTypeExcel8, "reports_query_final", strInputFileName, True
If MsgBox("Open spreadsheet in Excel?", vbYesNo, "Excel
Export") = vbYes Then
Set xl = CreateObject("Excel.Application")
xl.Workbooks.Add strInputFileName
xl.Visible = True
Set xl = Nothing
Else
MsgBox "Export complete"
End If
End If
End If
Exit Sub

ERR_Export:
MsgBox "An error has occured exporting data." & vbNewLine &
Err.Description & " " & Err.Number
Exit Sub
End Sub
 
C

crossb

I've switched to using DoCmd.OutTo. Is there any problems with doing
it this way instead?

DoCmd.OutputTo acOutputQuery, "Reports_Query_Final",
acSpreadsheetTypeExcel8, strInputFileName
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top