ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Loading a Reference (https://www.excelbanter.com/excel-programming/321828-loading-reference.html)

Scott

Loading a Reference
 
I need to load the "Microsoft ActiveX Data Objects 2.6 Library" when a
particular worksheet opens. I alreafdy plan to create an add-in to hold my
code and special menu.

Can VBA load a reference? Any links to examples?



Kou Vang[_2_]

Loading a Reference
 
In the VBA editor, go to Tools, References, then add the specific ADO.

Kou

Scott

Loading a Reference
 
I know how to do that, I was asking if it's possible with VBA.


"Kou Vang" wrote in message
...
In the VBA editor, go to Tools, References, then add the specific ADO.

Kou




Tom Ogilvy

Loading a Reference
 
http://support.microsoft.com/default...b;en-us;160647
XL97: How to Programmatically Create a Reference

applicable to Excel 97 and later.

--
Regards,
Tom Ogilvy


"scott" wrote in message
...
I know how to do that, I was asking if it's possible with VBA.


"Kou Vang" wrote in message
...
In the VBA editor, go to Tools, References, then add the specific ADO.

Kou






Scott

Loading a Reference
 
Hey Tom, I'm just trying to load a Reference Library of ADO 2.6, although
your link was helpful in another way.


"Tom Ogilvy" wrote in message
...
http://support.microsoft.com/default...b;en-us;160647
XL97: How to Programmatically Create a Reference

applicable to Excel 97 and later.

--
Regards,
Tom Ogilvy


"scott" wrote in message
...
I know how to do that, I was asking if it's possible with VBA.


"Kou Vang" wrote in message
...
In the VBA editor, go to Tools, References, then add the specific ADO.

Kou








Scott

Loading a Reference
 
i'm sorry, i think that's going to work. i though your link was just
accessing functions on another sheet.


"Tom Ogilvy" wrote in message
...
http://support.microsoft.com/default...b;en-us;160647
XL97: How to Programmatically Create a Reference

applicable to Excel 97 and later.

--
Regards,
Tom Ogilvy


"scott" wrote in message
...
I know how to do that, I was asking if it's possible with VBA.


"Kou Vang" wrote in message
...
In the VBA editor, go to Tools, References, then add the specific ADO.

Kou








Jamie Collins

Loading a Reference
 

scott wrote:
I need to load the "Microsoft ActiveX Data Objects 2.6 Library" when

a
particular worksheet opens.


Must it be ADO 2.6? Are you sure all your users have this version e.g.
what do you want to happen if they only have ADO 2.8? Rather than
setting a reference (early binding), you may be able to use late
binding e.g. instead of:

Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset

you could use:

Dim rs As Object
On Error Resume Next
Set rs = CreateObject("ADODB.Recordset")
If rs Is Nothing Then
MsgBox "ADO may not be installed."
....

AFAIK You cannot use CreateObject to specify a version; if a machine
has multiple versions, as does mine, you just get the most recently
installed version. With MDAC you can be assured the most recently
installed will have the highest version number.

If it must be ADO 2.6, you may want to check the registry for the
component's progid before attempting to set the reference.
Jamie.

--


NickHK

Loading a Reference
 
Jamie,
You can certainly:
Set obj1 = CreateObject("ADODB.Recordset.2.5")
Set obj2 = CreateObject("ADODB.Recordset.2.7")

That's if you really eanted to

NickHK

"Jamie Collins" wrote in message
oups.com...

scott wrote:
I need to load the "Microsoft ActiveX Data Objects 2.6 Library" when

a
particular worksheet opens.


Must it be ADO 2.6? Are you sure all your users have this version e.g.
what do you want to happen if they only have ADO 2.8? Rather than
setting a reference (early binding), you may be able to use late
binding e.g. instead of:

Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset

you could use:

Dim rs As Object
On Error Resume Next
Set rs = CreateObject("ADODB.Recordset")
If rs Is Nothing Then
MsgBox "ADO may not be installed."
...

AFAIK You cannot use CreateObject to specify a version; if a machine
has multiple versions, as does mine, you just get the most recently
installed version. With MDAC you can be assured the most recently
installed will have the highest version number.

If it must be ADO 2.6, you may want to check the registry for the
component's progid before attempting to set the reference.
Jamie.

--




Jamie Collins

Loading a Reference
 

NickHK wrote:

You can certainly:
Set obj1 = CreateObject("ADODB.Recordset.2.5")
Set obj2 = CreateObject("ADODB.Recordset.2.7")


For the recordset object, I have three registry keys:

HKEY_LOCAL_MACHINE\SOFTWARE\Classes\ADODB.Recordse t
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\ADODB.Recordse t.2.8
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\ADODB.Recordse t.2.7

However, they all share the same CLSID, so it doesn't matter which name
I use in CreateObject, I'll always get an object from the same
component.

My machine also has version ADO 2.6 available as a reference, but when
I try

Set obj1 = CreateObject("ADODB.Recordset.2.6")

I get the expected error, 'ActiveX component can't create object'.
Jamie.

--



All times are GMT +1. The time now is 05:39 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com