Visual Basic

Moderators: None (Apply to moderate this forum)
Number of threads: 18011
Number of posts: 55384

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Object missing?? in an ADO open connection CLASS Posted by eatc7402 on 20 Jun 2006 at 1:33 PM
I have the following code in a MODULE.

' Open a connection.
Set myconn = New ADODB.connection
myconn.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & DB_Path_File_param & ";" & _
"Persist Security Info=False"
myconn.Open
myconn.CursorLocation = adUseClient
'-------------------------------------------------------------

ListFields(myconn, tbl_or_qry_selected_item)

It works fine.

I then attempted to make the 'open connection' code
into a CLASS, like this:
'--------------------------------------------------------
Public Function Open_ADO_conn_to_Jet(Path_Filename As String) As Object
Dim connection As ADODB.connection
' Open a connection.
Set connection = New ADODB.connection
connection.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Path_Filename & ";" & _
"Persist Security Info=False"
connection.Open
connection.CursorLocation = adUseClient

Open_ADO_conn_to_Jet = connection

End Function
'-----------------------------------------------------------------

and THEN call the function with this
Set DB_Hookup_dbf = New DB_Class_dbf

Set myconn = DB_Hookup_dbf.Open_ADO_conn_to_Jet (DB_Path_File_param)

The DB_Path_File_param passed is okay.

BUT this results in a 424 Runtime error, of OBJECT REQUIRED. I am somewhat miffed
by just what I have done incorrectly here. Where am I missing an object here?

eatc7402
DaveF.
Report
Re: Object missing?? in an ADO open connection CLASS Posted by infidel on 21 Jun 2006 at 7:09 AM
This message was edited by infidel at 2006-6-21 7:10:52

: Open_ADO_conn_to_Jet = connection

You forgot the "Set".

Also, the class is named Connection, and it's not a good idea to name a variable the same name as a class or type. This may not be an actual problem with your code in this case, but it's still not a good idea.

infidel

$ select * from users where clue > 0
no rows returned







 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.