R
Rico
Hello,
I have an Excel 2007 document that I'm trying to create an import function
for using DAO to read the file. The problem is, it only works when I have
the Excel document open. IF I close Excel, I get a err.number 91 "Object
variable or with block...." and if I change the "Excel 8.0" to "Excel 12.0",
I get a "Couldn't find installable ISAM" error. Any ideas? Here is the
code I'm working with.
Public Function OpenExcelDAO(ByVal strPath As String) As DAO.Recordset
On Error GoTo Catch
Dim dbtmp As DAO.Database
Dim tblObj As DAO.TableDef
Dim rs As DAO.Recordset
Dim strFirstName As String
'If there is nothing to import, then exit
If Not FileExists(strPath) Then GoTo Finally
Set dbtmp = OpenDatabase(strPath, False, True, "Excel 8.0; ")
Set rs = dbtmp.OpenRecordset("select * from `" &
dbtmp.TableDefs(0).Name & "`")
Set OpenExcelDAO = rs
Set rs = Nothing
Set dbtmp = Nothing
Finally:
Exit Function
Catch:
LogError Err.Number, Err.Description, mstrModule, "OpenExcelDAO"
Resume Finally
Resume
End Function
Thanks!
I have an Excel 2007 document that I'm trying to create an import function
for using DAO to read the file. The problem is, it only works when I have
the Excel document open. IF I close Excel, I get a err.number 91 "Object
variable or with block...." and if I change the "Excel 8.0" to "Excel 12.0",
I get a "Couldn't find installable ISAM" error. Any ideas? Here is the
code I'm working with.
Public Function OpenExcelDAO(ByVal strPath As String) As DAO.Recordset
On Error GoTo Catch
Dim dbtmp As DAO.Database
Dim tblObj As DAO.TableDef
Dim rs As DAO.Recordset
Dim strFirstName As String
'If there is nothing to import, then exit
If Not FileExists(strPath) Then GoTo Finally
Set dbtmp = OpenDatabase(strPath, False, True, "Excel 8.0; ")
Set rs = dbtmp.OpenRecordset("select * from `" &
dbtmp.TableDefs(0).Name & "`")
Set OpenExcelDAO = rs
Set rs = Nothing
Set dbtmp = Nothing
Finally:
Exit Function
Catch:
LogError Err.Number, Err.Description, mstrModule, "OpenExcelDAO"
Resume Finally
Resume
End Function
Thanks!