Solved

Why is this VBA failing?

Posted on 2011-09-07
10
227 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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
 

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

777 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