I am running Access 2007. I have created a query that I use in my code for the creation of a spreadsheet. The query runs without any problems and gives the proper results.
When I output the query to an Excel spreadsheet it works fine (see option 1 in attached code). When I attempt to output the results to a "CSV" file, I get the 3828 error code (shown in attachment) (see option 2 in attached code).
My goal is to output the information to a CSV file then import the CSV file into an Excel template with an Excel macro. This way the file I present to the customer will be formatted to their liking.
This is running the exact same query in both instances. One works and the other does not. I tried removing the specification file and I still get the error.
Can anyone help in resolving this issue?
Thanks.
Ed Torasso
[imgnothumb]http://bytes.com/attachment.php? attachmentid=75 73[/imgnothumb]
When I output the query to an Excel spreadsheet it works fine (see option 1 in attached code). When I attempt to output the results to a "CSV" file, I get the 3828 error code (shown in attachment) (see option 2 in attached code).
My goal is to output the information to a CSV file then import the CSV file into an Excel template with an Excel macro. This way the file I present to the customer will be formatted to their liking.
This is running the exact same query in both instances. One works and the other does not. I tried removing the specification file and I still get the error.
Can anyone help in resolving this issue?
Thanks.
Ed Torasso
Code:
Private Sub cmdExport_Click()
'* * * * * * * * * _NEW_FORMAT_USING_CSV_FILE * * * * * *
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
'**********************
'SET OPTION HERE TO RUN ONE OF THE TRANSFER TYPES FOR TESTING
intOption = 2
'***********************
strFolderPath = GetPath("Export")
If strFolderPath = "ERROR" Then
Exit Sub
End If
strAppPath = CurrentProject.path & "\"
If intOption = 1 Then
'CODE TO TRANSFER SPREADSHEET *** THIS WORKS FINE
strFolderPath = strFolderPath & Me.BusinessName & " " & Format(Now, "mm-dd-yyyy") & ".xlsx"
On Error Resume Next
Kill strFolderPath 'DELETE EXISTING FILE IF IT EXISTS
On Error GoTo Err_cmdExport_Click
DoCmd.OutputTo acOutputQuery, "qryBusinessExport_Consolidated", acFormatXLSX, strFolderPath, False, "", 0, acExportQualityPrint
Set XL = CreateObject("Excel.Application")
Set wbk = XL.Workbooks.Open(strFolderPath)
XL.Visible = True
Set wbk = Nothing
Set XL = Nothing
Else
'CODE TO CREATE CSV FILE TO LOAD TO TEMPLATE - *** THIS FAILS WITH ERROR 3828
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.TransferText acExportDelim, "BusinessExportConsolidated", "qryBusinessExport_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
End If
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
Comment