ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   share adodb connection in excel (https://www.excelbanter.com/excel-programming/309063-share-adodb-connection-excel.html)

Marek

share adodb connection in excel
 
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

--
Message posted from http://www.ExcelForum.com


Jamie Collins

share adodb connection in excel
 
Marek wrote ...

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.

--

Marek

share adodb connection in excel
 
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

--
Message posted from http://www.ExcelForum.com


Jamie Collins

share adodb connection in excel
 
Marek wrote ...

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.

--


All times are GMT +1. The time now is 06:53 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com