Solved

Why is this VBA failing?

Posted on 2011-09-07
10
248 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 47

Expert Comment

by:Martin Liss
ID: 36498881
What is the error?
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
This article helps those who get the 0xc004d307 error when trying to rearm (reset the license) Office 2013 in a Virtual Desktop Infrastructure (VDI) and/or those trying to prep the master image for Microsoft Key Management (KMS) activation. (i.e.- C…
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 …
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

705 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