Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compile Error User - Defined Type not defined

Status
Not open for further replies.

Costefran

Technical User
Jan 2, 2008
197
GB
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 have looked at tools / references but not sure which object library to select" You could have provided us with the list that are currently selected.

Is the Microsoft Excel xx.0 Object Library selected? xx corresponds to your version of Excel. For instance 11 is Office 2003.

Duane
Hook'D on Access
MS Access MVP
 
The Excel object library is now selected and it works!

Many Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top