Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access wont export excel table 64bit

Status
Not open for further replies.

Lewis0072

MIS
Apr 7, 2011
3
GB
Hi Guys,

Here is the code i have, i dont know why but this just wont work in 64bit versions of Windows.
Works fine in 32bit.
I have looked all over with no joy, im at a complete loss.
Any help would be much apreciated.

I think it has something to do with the Highlighted (red) text

'################################################################################################
'Begin Local bespoke procedures
'################################################################################################

'------------------------------------------------------------------------------------------------
'Export a table with data dependant on fields chosen for inclusion, and criteria for selection.
'------------------------------------------------------------------------------------------------
Private Sub ExportTable(Optional ByVal strExportSQL As String)
Dim dbExport As Database 'Interface to current database
Dim qdfExport As QueryDef 'Interface to final query
Dim strError2501 As String
Dim strError2302 As String
Dim strError2306 As String

strError2501 = "There was an error while trying to create an output file. The file was not created."

strError2302 = "The file location you selected appears to be invalid" _
& Chr(10) & Chr(13) _
& "This may be because the exisiting file is open, please close it and try again."

strError2306 = "Access cannot cope with an output of this size" _
& Chr(10) & Chr(13) & Chr(10) & Chr(13) _
& "You should limit the number of records in the output to less than 16,000 OR" _
& Chr(10) & Chr(13) _
& "Copy records from the query: " & OUTPUT_QUERY_NAME _
& " using a different method?"

On Local Error GoTo Err_ExportTable
'Set up screen status
Call StatusBarMsg("Exporting data to table now, please wait...")
Call DoCmd.Echo(False)
Call DoCmd.Hourglass(True)

Set dbExport = CurrentDb

'Get SQL for output query if a query string was not passed
'--------------------------------------------------------------------------------------------
If strExportSQL = vbNullString Then strExportSQL = GetExportSQL

'Output Final Query
'--------------------------------------------------------------------------------------------
'Check output query is not open (would cause error) then delete so new one can be saved
If QueryExists(OUTPUT_QUERY_NAME) = True Then
If QueryIsLoaded(OUTPUT_QUERY_NAME) = True Then
Call DoCmd.Close(acQuery, OUTPUT_QUERY_NAME, acSaveNo)
End If
Call DoCmd.DeleteObject(acQuery, OUTPUT_QUERY_NAME)
End If

'Create output query
Set qdfExport = dbExport.CreateQueryDef(OUTPUT_QUERY_NAME, strExportSQL)

'Check whether a maximum number of schools was required
'If so then edit output file accordingly
If Not IsNull(Me.txtMaxSchools) Then Call Limit_Number_Of_Schools

'Output as Excel file (asking for location)
Call DoCmd.OutputTo(acOutputQuery, OUTPUT_QUERY_NAME, acFormatXLS, , True)

'Error Handling
'------------------------------------------------------------------------------------------------
Exit_ExportTable: 'Label to resume after error.
'Screen re-paint ON
Call DoCmd.Echo(True)
Call ClearStatusBarMsg

Set qdfExport = Nothing
Set dbExport = Nothing

Call DoCmd.Hourglass(False)
Exit Sub

Err_ExportTable: 'Label to jump to on error
Dim objComm As clsCommonDialog
Dim intChoice As Integer
Dim strFileName As String

Call DoCmd.Echo(True)

Select Case Err.Number
Case 2501
MsgBox strError2501, vbExclamation, "Cannot save Excel output file"
Resume Next
Case 2302 'Permission denied / file not found
MsgBox strError2302, vbExclamation + vbOKOnly, "Cannot save Excel output file"
Resume Exit_ExportTable
Case 2306 'Stack overflow
intChoice = MsgBox(strError2306, vbQuestion + vbOKCancel)

'If user selects OK then export to Excel using the TransferSpreadsheet method
If intChoice = vbOK Then
Set objComm = New clsCommonDialog

If objComm.VBGetSaveFileName(strFileName, "", True, "Excel Spreadsheet (*.xls)|*.xls") = True Then
Call DoCmd.TransferSpreadsheet(acExport, acSpreadsheetTypeExcel9, OUTPUT_QUERY_NAME, strFileName)
End If

Set objComm = Nothing
End If

Resume Exit_ExportTable
Case Else
MsgBox "Error " & Err.Number & " - " & Err.Description, vbExclamation
Resume Exit_ExportTable

End Select
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top