Solved

Why is this VBA failing?

Posted on 2011-09-07
10
240 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 47

Expert Comment

by:Martin Liss
ID: 36498881
What is the error?
0
Technology Partners: 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!

 
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

Industry Leaders: 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 descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

733 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