I have code that runs successfully in Access 2010 (64 bit) that does not run in Access 2013 (64 bit). It fails when attempting to open a query that exists on the database. The query shown in the screen shot below exists on the database. I can manually run the query without any issues. When I run the code shown below in Access 2010, it runs without any errors and produces the results into an Excel file. When I run the same exact same database in Access 2013 on a Windows 2012 server I get a error code 3011 when it attempts to open the same query, stating that the query cannot be found.
A copy of the code is shown below. The highlighted line is where the error occurs. Is there something different that needs to be done in Access 2013 vs Access 2010? Any thoughts??
Any help would be appreciated.
Thanks, Ed
Code:
Private Sub cmdExport_Click()
On Error GoTo Err_cmdExport_Click
Dim XL As Object
Dim wbk As Object
Dim strFolderPath As String
Dim strAppPath As String
Dim intOption As Integer
strFolderPath = GetPath("Export")
If strFolderPath = "ERROR" Then
Exit Sub
End If
strAppPath = CurrentProject.path & "\"
' * * * CODE TO CREATE CSV FILE TO LOAD TO TEMPLATE
strFolderPath = strFolderPath & Me.BusinessName & " " & Format(Now, "mm-dd-yyyy") & ".xlsm"
On Error Resume Next
Kill strFolderPath '***DELETE EXISTING FILE IF IT EXISTS
On Error GoTo Err_cmdExport_Click
DoCmd.SetWarnings False
DoCmd.RunSQL "DELETE tmpExport_Consolidated.* FROM tmpExport_Consolidated"
DoCmd.OpenQuery "qryBusinessExport_Consolidated", acViewNormal
DoCmd.SetWarnings True
DoCmd.TransferText acExportDelim, , "tmpExport_Consolidated", strAppPath & "custExport.csv", False, ""
' Create Formatted Spreadsheet
Set XL = CreateObject("Excel.Application")
XL.Workbooks.Open strAppPath & "DatabaseExport_Consolidated_Template.xlsm"
XL.Run "Module1.ImportData"
XL.ActiveWorkbook.SaveAs strFolderPath
XL.Visible = True
Set XL = Nothing
MsgBox "Extract file has been created at the following directory path:" & vbCrLf & vbCrLf & strFolderPath, vbInformation, "Export Completed"
Exit_cmdExport_Click:
Exit Sub
Err_cmdExport_Click:
If Err.Number = 2302 Then
MsgBox "The " & Me.BusinessName & " " & Format(Now, "mm-dd-yyyy") & ".xls file is currently opened. Please close the file " & _
"in order to process this export request.", vbCritical, "File Open Error"
Else
MsgBox ErrorMessage(Me.Name, "cmdExport_Click") & Err.Number & " - " & Err.description, vbInformation, "System Code Error"
End If
Resume Exit_cmdExport_Click
End Sub