Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ADO on load connection 1

Status
Not open for further replies.

timhans

Programmer
Jun 24, 2009
75
Hello, I am following a example in a book on how to ADO connect with on load event. The book I am using is for Access 2007(I have at home and do most of my work) and puts the following in a class module:

'Declare connection object variable
Dim cnn As New ADODB.Connection

'Declare Recordset object variable
Dim rs As New ADODB.Recordset

At work(where I will be using it) I use Access 2003, will the above cause an error in access 2003, an older book connects with out the New, just

Dim cnn As ADODB.Connection

Trying to write in a way that access 2003 is o.k with.
Thanks for any insight
 
Your posted code seems correct for ac2003.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
It won't cause an error (as PHV states) it's about the way an object is instantiated.

The example in the older book (I assume it's got a Set cnn = New ADODB.Connection somewhere) is faster * as the VB engine knows the object is instantiated (where as if you use Dim ... as New ... it will check everytime the object is used to see if has been instantiated, it treats the variable as an auto-instantiated variable).

* Not that you will notice the speed difference as it's miniscule. Just though it worth pointing out the difference in the declarations.

Hope this helps

HarleyQuinn
---------------------------------
Black coat, white shoes, black hat, cadillac. The boy's a timebomb!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before post
 
Thanks for responding HarleyQuinn. So if I understand use
Set cnn = New ADODB.Connection
if so then no need to Dim cnn As ADODB.Connection. Thanks
 
That's not quite what I was driving at, if you set the object to a NEW connection
Code:
Set cnn = New ADODB.Connection
You will still have to dimension it first
Code:
Dim cnn As ADODB.Connection
You just won't use the NEW keyword when you dimension/declare it.

HarleyQuinn
---------------------------------
Black coat, white shoes, black hat, cadillac. The boy's a timebomb!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before post
 
Glad I could help, thanks for the star [smile]

HarleyQuinn
---------------------------------
Black coat, white shoes, black hat, cadillac. The boy's a timebomb!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before post
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top