Why is this VBA failing?

I am very new to VBA and need to use an event to establish a database connection. But it's throwing an error when I add in this code:

Dim Myconnection As Connection
    Dim Myrecordset As Recordset
    Dim MyWorkbook As String

Why? These are just variable definitions. RIght?

Confused...

Thanks!
newbiewebSr. Software EngineerAsked:
Who is Participating?
 
zorvek (Kevin Jones)ConsultantCommented:
Before writing any ADODB code the data objects library "Microsoft ActiveX Data Objects x.x Library" must be referenced in the VBA project (Tools->References).

Kevin
0
 
newbiewebSr. Software EngineerAuthor Commented:
I find the User Type not defined is the error. How do I define it?
0
 
Martin LissOlder than dirtCommented:
What is the error?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
GrahamSkanRetiredCommented:
You need to set a reference to the appropriate library, i.e. the Microsoft Active Data Objects x.x Library.
0
 
newbiewebSr. Software EngineerAuthor Commented:
Thanks. How do I reference it in Excel 2007?
0
 
newbiewebSr. Software EngineerAuthor Commented:
I do not see Tools.
0
 
zorvek (Kevin Jones)ConsultantCommented:
It's in the VBE menus, not the Excel application menus.

Kevin
0
 
newbiewebSr. Software EngineerAuthor Commented:
Is that a button? Where is Tools in Excel 2007?
0
 
zorvek (Kevin Jones)ConsultantCommented:
While looking at the Excel workbook, press ALT+F11 to switch to the VBE. You will then see the Tools menu.

Kevin
0
 
newbiewebSr. Software EngineerAuthor Commented:
Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.