Can anyone please help with the following
I am trying open an excel application and worksheet through a function but I get the error Compile Error User - Defined type not defined. The problem is is that my code did work and now doesn't I have carried out some research and think it may be something to do with the Object Library?
I have looked at tools / references but not sure which object library to select
For reference my code is below
Function OpenSpecific_xlFile()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim sFullPath As String
'Set db = DAO.DBEngine.Workspaces(0).OpenDatabase( _
"C:\database.mdb")
Set db = CurrentDb
Set rs = db.OpenRecordset("" & Forms![Log In Form]![Name] & " Table" & "", dbOpenSnapshot)
'Start a new workbook in Excel
Dim oApp As New Excel.Application
Dim oBook As Excel.Workbook
Dim oSheet As Excel.Worksheet
sFullPath = Forms![Log In Form]![Log In Form Query for Subform].Form![File Path for Spend Reports] & "\Work Schedule Report Spreadsheet2.xls"
Set oBook = oApp.Workbooks.Open(sFullPath)
'Set oBook = oApp.Workbooks.Add
Set oSheet = oBook.Worksheets(1)
oSheet.Range("A9:X6123").ClearContents
'Add the data starting at cell A9
oSheet.Range("A9").CopyFromRecordset rs
oApp.Visible = True
oApp.UserControl = True
'Close the Database and Recordset
rs.Close
db.Close
End Function
I am trying open an excel application and worksheet through a function but I get the error Compile Error User - Defined type not defined. The problem is is that my code did work and now doesn't I have carried out some research and think it may be something to do with the Object Library?
I have looked at tools / references but not sure which object library to select
For reference my code is below
Function OpenSpecific_xlFile()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim sFullPath As String
'Set db = DAO.DBEngine.Workspaces(0).OpenDatabase( _
"C:\database.mdb")
Set db = CurrentDb
Set rs = db.OpenRecordset("" & Forms![Log In Form]![Name] & " Table" & "", dbOpenSnapshot)
'Start a new workbook in Excel
Dim oApp As New Excel.Application
Dim oBook As Excel.Workbook
Dim oSheet As Excel.Worksheet
sFullPath = Forms![Log In Form]![Log In Form Query for Subform].Form![File Path for Spend Reports] & "\Work Schedule Report Spreadsheet2.xls"
Set oBook = oApp.Workbooks.Open(sFullPath)
'Set oBook = oApp.Workbooks.Add
Set oSheet = oBook.Worksheets(1)
oSheet.Range("A9:X6123").ClearContents
'Add the data starting at cell A9
oSheet.Range("A9").CopyFromRecordset rs
oApp.Visible = True
oApp.UserControl = True
'Close the Database and Recordset
rs.Close
db.Close
End Function