I have an Access 16.0 database and am trying to import an Excel spreadsheet into the database.
This has worked perfectly fine until now... and, I haven't changed any of the code.
The database seems to lock up, and then exits the database, when it's first attempting to read the file.
I have a reference to the Excel 16.0 Object Library.
Does anyone know if there's an issue with Access? I.e., with a recent update or something? Any other thoughts?
Here's my code...
Class level declarations:
Dim ExcelApplication As Excel.Application
Dim ExcelWorkbook As Excel.Workbook
Dim ExcelRange As Excel.Range
My Connect to Excel code (the Excel spreadsheet is password protected):
On Error Resume Next
Set ExcelApplication = GetObject(, "Excel.Application")
If Err.Number <> 0 Then
Err.Clear
On Error GoTo 0
Set ExcelApplication = CreateObject("Excel.Application")
End If
ExcelApplication.Visible = True
If ExcelPassword <> "" Then
Set ExcelWorkbook = ExcelApplication.Workbooks.Open(FileToImport, , , , ExcelPassword)
If Err.Number <> 0 Then Set ExcelWorkbook = ExcelApplication.Workbooks.Open(FileToImport)
Else
Set ExcelWorkbook = ExcelApplication.Workbooks.Open(FileToImport)
End If
I check the Excel file, by checking the column headings, to make sure the Excel file is in proper format. It's locking up when it's attempting to set AHeader. Here's the code:
Dim AHeader As String
Dim BHeader As String
Dim CHeader As String
Dim DHeader As String
Dim EHeader As String
Dim FHeader As String
Dim GHeader As String
AHeader = UCase(ExcelWorkbook.Worksheets(1).Range("A7").Value)
BHeader = UCase(ExcelWorkbook.Worksheets(1).Range("B7").Value)
CHeader = UCase(ExcelWorkbook.Worksheets(1).Range("C7").Value)
DHeader = UCase(ExcelWorkbook.Worksheets(1).Range("D7").Value)
EHeader = UCase(ExcelWorkbook.Worksheets(1).Range("E7").Value)
FHeader = UCase(ExcelWorkbook.Worksheets(1).Range("F7").Value)
GHeader = UCase(ExcelWorkbook.Worksheets(1).Range("G7").Value)
GetIfImportFileInProperOrder = AHeader = "POLICY" And _
BHeader = "POLICY TYPE" And _
CHeader = "CT" And _
DHeader = "DEPT" And _
EHeader = "EMPLOYEE/MEMBER#" And _
FHeader = "NAME" And _
GHeader = "PREMIUM BILLED"
Please keep in mind that all this code has NOT changed at all since it last worked.
Thanks in advance for your help.