Solved

Why is this VBA failing?

Posted on 2011-09-07
10
205 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
Comment Utility
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
Comment Utility
I find the User Type not defined is the error. How do I define it?
0
 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
What is the error?
0
 
LVL 76

Assisted Solution

by:GrahamSkan
GrahamSkan earned 100 total points
Comment Utility
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
Comment Utility
Thanks. How do I reference it in Excel 2007?
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:newbieweb
Comment Utility
I do not see Tools.
0
 
LVL 81

Expert Comment

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

Kevin
0
 

Author Comment

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

Expert Comment

by:zorvek (Kevin Jones)
Comment Utility
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
Comment Utility
Thanks!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

772 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

10 Experts available now in Live!

Get 1:1 Help Now