Forum Discussion
mzeller1776
Dec 18, 2024Copper Contributor
Getting Run Time Error 2302 Access can't save output to file you've selected
I have an Event Procedure that runs off of a control button being clicked. The below screenshot shows what's in the event procedure. I'm getting a run time error 2302 stating Access can't save the output data to the file you've selected. Any idea why?
Private Sub Command230_Click()
'Define output location variables
Dim strFullPathMatches As String
Dim strFullPathNoMatches As String
strFullPathMatches = "I:\Customer Operations-Core\Operational QA\Dispute Services Verification\2025 DPP Verification\Correspondence Verification"
strFullPathNoMatches = "I:\Customer Operations-Core\Operational QA\Dispute Services Verification\2025 DPP Verification\Correspondence Verification"
Me.Dirty = False
'Run queries and output to Excel
DoCmd.OutputTo acOutputQuery, "QryCorrespondenceMatches", acFormatXLS, strFullPathMatches, True
DoCmd.OutputTo acOutputQuery, "QryCorrespondenceNoMatches", acFormatXLS, strFullPathNoMatches, True
'Run delete queries to clear out the MS Access tables to prepare for next run
DoCmd.OpenQuery "QryDeleteLetterStatusRecs"
DoCmd.OpenQuery "QryDeleteCorrespondenceRecs"
End Sub
- mzeller1776Copper Contributor
Thanks.
- NikolinoDEGold Contributor
The Run-Time Error 2302 in Access usually occurs when the application cannot save the output to the specified location or file for several potential reasons. Here are some common causes and troubleshooting steps you can use to resolve this issue.
The output location path (strFullPathMatches and strFullPathNoMatches) you are using is incorrect, inaccessible, or doesn't include a file name with an appropriate extension.
Ensure that the path includes a valid file name and extension (e.g., .xls or .xlsx).
To resolve this, you need to add a file name and extension to the paths like these:
strFullPathMatches = "I:\Customer Operations-Core\Operational QA\Dispute Services Verification\2025 DPP Verification\CorrespondenceMatches.xlsx"
strFullPathNoMatches = "I:\Customer Operations-Core\Operational QA\Dispute Services Verification\2025 DPP Verification\CorrespondenceNoMatches.xlsx"
Please have in mind that Windows has a maximum path length limitation (260 characters). If your path is too long, Access may fail to save the file.
Here's a revised version (a example) of your code with debugging messages to help identify the problem:
Private Sub Command230_Click() ' Define output location variables Dim strFullPathMatches As String Dim strFullPathNoMatches As String strFullPathMatches = "I:\Customer Operations-Core\Operational QA\Dispute Services Verification\2025 DPP Verification\CorrespondenceMatches.xlsx" strFullPathNoMatches = "I:\Customer Operations-Core\Operational QA\Dispute Services Verification\2025 DPP Verification\CorrespondenceNoMatches.xlsx" Me.Dirty = False ' Debugging messages to verify paths Debug.Print "Saving to: " & strFullPathMatches Debug.Print "Saving to: " & strFullPathNoMatches ' Run queries and output to Excel On Error GoTo ErrorHandler DoCmd.OutputTo acOutputQuery, "QryCorrespondenceMatches", acFormatXLSX, strFullPathMatches, True DoCmd.OutputTo acOutputQuery, "QryCorrespondenceNoMatches", acFormatXLSX, strFullPathNoMatches, True ' Run delete queries to clear out the MS Access tables DoCmd.OpenQuery "QryDeleteLetterStatusRecs" DoCmd.OpenQuery "QryDeleteCorrespondenceRecs" MsgBox "Export completed successfully!", vbInformation Exit Sub ErrorHandler: MsgBox "Error: " & Err.Number & " - " & Err.Description, vbCritical End Sub
Hope this information can help you a little with your plans...if not, please just ignore it.