Hi All,
I am having a problem with an Excel to Access import (2003). I have a form with two command buttons. The first button when clicked opens the Excel spreadsheet for viewing before it is sent to an Access table. The second command button, deletes all the records in the Access table and imports all the recoded for the spreadsheet.
The issue is that after I run the routine once. The second time I run it the Excel spreadsheet errors with “spreadsheet is locked for editing, open read only.” At this point, the spreadsheet is not open and Excel is not open. My question - is there some way to make sure the Excel spreadsheet is released so the error does not occur? I looked at the KILL option in Access but that would delete the Excel spreadsheet, which I do not want to do.
As always, maybe I am going about this all wrong. Any suggestions will be appreciated.
Thanks
Dom
I am having a problem with an Excel to Access import (2003). I have a form with two command buttons. The first button when clicked opens the Excel spreadsheet for viewing before it is sent to an Access table. The second command button, deletes all the records in the Access table and imports all the recoded for the spreadsheet.
The issue is that after I run the routine once. The second time I run it the Excel spreadsheet errors with “spreadsheet is locked for editing, open read only.” At this point, the spreadsheet is not open and Excel is not open. My question - is there some way to make sure the Excel spreadsheet is released so the error does not occur? I looked at the KILL option in Access but that would delete the Excel spreadsheet, which I do not want to do.
As always, maybe I am going about this all wrong. Any suggestions will be appreciated.
Thanks
Dom
Code:
Private Sub cmdOpenExcel_Click()
On Error GoTo Err_cmdOpenExcel_Click
Dim retVal As Variant
retVal = Shell("Excel " & Chr(34) & "\\bigguy\users\dom_f\Access\TestWebPAS2\TESTwebpas_download1.xls" & Chr(34), vbMaximizedFocus)
Exit_cmdOpenExcel_Click:
Exit Sub
Err_cmdOpenExcel_Click:
MsgBox Err.Description
Resume Exit_cmdOpenExcel_Click
End Sub
Code:
Private Sub cmdImportRecords_Click()
On Error GoTo Err_cmdImportRecords_Click
Dim strDelete As String
strDelete = "DELETE WebPAS.*, * FROM WebPAS"
DoCmd.RunSQL strDelete
Call ImportExcelToAccess
Exit_cmdImportRecords_Click:
Exit Sub
Err_cmdImportRecords_Click:
MsgBox Err.Description
Resume Exit_cmdImportRecords_Click
End Sub
Code:
Function ImportExcelToAccess()
On Error GoTo ImportExcelToAccess_Err
DoCmd.TransferSpreadsheet acImport, 8, "WebPAS", "\\bigguy\users\dom_f\Access\TestWebPAS2\TESTwebpas_download1.xls", True, ""
ImportExcelToAccess_Exit:
Exit Function
ImportExcelToAccess_Err:
MsgBox Error$
Resume ImportExcelToAccess_Exit
End Function