Hi, I am trying to write a standalone function that opens a connection to Access and keeps it open until another function closes it... I am trying to call this function from another function(s) multiple times so Id like to open it and leave it accessible to other Subs or Functions...
So far I have this but it errors out, the problem I see is how do other function see that the connection is opened and use it... thanks for any help.
So far I have this but it errors out, the problem I see is how do other function see that the connection is opened and use it... thanks for any help.
Code:
Const ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source="&QuaccessDB & ";Persist Security Info=False"
FUNCTION OpenConnection()
Dim CN as New ADODB Connection
CN.Open ConnectionString
END FUNCTION
Code:
FUNCTION n_Days_Performance()
query = ' my query to run'
'Open Connection to Access DB via Function
OpenConnection
Dim RS as New ADODB RecordSet
rs.Open query, CN
'Do calculations based on returned data'
result = (cal1/cal2)/cal3
n_Days_Performance = result
END FUNCTION