Here's how I would do it; in fact, I recently finished a project that
leverages this technique.
Sub Proc1(aConn As ADODB.Connection)
Dim aRS As ADODB.Recordset
aRS.Open "{appropriate argument}", aConn
'...
End Sub
Sub Proc2(aConn As ADODB.Connection)
Dim aRS As ADODB.Recordset
aRS.Open "{appropriate argument}", aConn
'...
End Sub
Sub Main()
Dim aConn As ADODB.Connection
aConn.Open 'appropriate arguments
Proc1 aConn
Proc2 aConn
End Sub
--
Regards,
Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions
In article ,
says...
I have several procedures that use ADO to connect to a
database and retrieve Recordsets. In each of these
procedures I open a Connection, use some SQL to get the
Recordset, then close the Connection.
Since all of the procedures are using the same Connection
to the same database, it seems I should be able to open
the Connection once, have all my procedures use that
Connection, then close and destroy the object when I'm
done.
My initial idea as to have a class module that I use to
create that instance. But.... that's where I reach the
cul de sac on my knowledge of this topic.
Any help?
tod