Information générale
Catégorie:
Bases de données DAO/RDO/ODBC/ADO
Titre:
ADODB.Connection and Class Modules
I work with FoxPro, Access and SQL databases. When I write programs I need to determine at run time what the database I am working with is and then create the connection based on the database. I decided to create a Class Module to create the connection. I created a property called DataBase and depending upon which database it is the appropriate driver is used and the connection is opened.
It seems to be working ok. I can test for the state of the connection and it will be open. The problem I am running into is when I try to use the connection to open an ADODB.Recordset I am getting Error # 3001: Arguments are of the wrong type, out of acceptable range or in conflict with each other.
Example Code:
Dim cn as DataConnect 'Class Module - set as MultiUse
Dim rs as ADODB.Recordset
Set cn = New DataConnect
'Set the database type and path
cn.database = "access"
cn.datapath = "c:\test\test.mdb"
'Open connection return True if success
If cn.open_connection = False Then
MsgBox "Connection not Created."
Else
'if successful open then open recordset
rs.open "TableName", cn
End If
-------
Is it possible to use a Class Module with ADODB.Connection? Is cn not considered an ActiveConnection because it is a class module?
Thanks,
Nichole
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement