share adodb connection in excel

M

Marek

people in asp i can share adodb connection in GLOBAL .asa file

but i dont want to dedscribe adodb connection in each sub procedure

where in excel i can place my adodb connection desciption once onl
????


thank
 
J

Jamie Collins

Marek said:
people in asp i can share adodb connection in GLOBAL .asa file

but i dont want to dedscribe adodb connection in each sub procedure

where in excel i can place my adodb connection desciption once only
????

Dim the connection variable at the top of the code module (General
Declarations) e.g.

Private m_Con As ADODB.Connection

If the connection is required in more than one code module, provide a
Property Get e.g.

Friend Property Get Connection() As ADODB.Connection
Set Connection = m_Con
End Property

Jamie.

--
 
M

Marek

in my module i want to have variable with connection parameters

for example i want to once describe this variable somewhere in module

cons = "provider=Microsoft.Jet.OLEDB.4.0;" & _
"data source=db.mdb;"


and after that i simply want to use this string variable in each sub


maybe i must to use constants
 
J

Jamie Collins

Marek said:
in my module i want to have variable with connection parameters

for example i want to once describe this variable somewhere in module

cons = "provider=Microsoft.Jet.OLEDB.4.0;" & _
"data source=db.mdb;"

and after that i simply want to use this string variable in each sub

maybe i must to use constants ?

Sure, that's what I'd do:

Private Const CONN_STRING As String = "" & _
"provider=Microsoft.Jet.OLEDB.4.0;" & _
"data source=db.mdb;"

although it's unlikely to be needed by multiple subs e.g. if you have
a property that supplies the ADO Connection object.

Jamie.

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top