Solved

Why is this VBA failing?

Posted on 2011-09-07
10
216 Views
Last Modified: 2012-06-27
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!
0
Comment
Question by:newbieweb
10 Comments
 
LVL 81

Accepted Solution

by:
zorvek (Kevin Jones) earned 400 total points
ID: 36498877
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
 

Author Comment

by:newbieweb
ID: 36498880
I find the User Type not defined is the error. How do I define it?
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 36498881
What is the error?
0
 
LVL 76

Assisted Solution

by:GrahamSkan
GrahamSkan earned 100 total points
ID: 36498887
You need to set a reference to the appropriate library, i.e. the Microsoft Active Data Objects x.x Library.
0
 

Author Comment

by:newbieweb
ID: 36498891
Thanks. How do I reference it in Excel 2007?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:newbieweb
ID: 36498900
I do not see Tools.
0
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 36498909
It's in the VBE menus, not the Excel application menus.

Kevin
0
 

Author Comment

by:newbieweb
ID: 36498918
Is that a button? Where is Tools in Excel 2007?
0
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 36498931
While looking at the Excel workbook, press ALT+F11 to switch to the VBE. You will then see the Tools menu.

Kevin
0
 

Author Closing Comment

by:newbieweb
ID: 36498946
Thanks!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
Outlook Free & Paid Tools
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now