pass in ADODB connection

G

Guest

I want to optionally pass in an open ADODB connection vs open a new one in a
function. How do I set my function arguments:

Optional cnnIn as adodb.Connetion = ?

And then in the function, how do I check to see if something was passed in?
Am I going about this wrong? I just want to use an open connection sometimes
and open a new connection other times. Thanks for the help.
 
D

Douglas J Steele

Try

Optional cnnIn as adodb.Connetion = Nothing

then check in your code

If cnnln Is Nothing Then
' you need to set it
Else
' it was passed in
End If
 
A

Allen Browne

Hi Sam

If no argument is passed in, the uninitialized object will be Nothing:

Function MyFunction(Optional cnnIn As ADODB.Connection)
If cnnIn Is Nothing Then
Set cnnIn = New ADODB.Connection
Set cnnIn = ...
End If
'Do something
End Function

You could also use a Variant and test if the argument is Missing:

Function MyFunc(Optional varCnn As Variant)
If IsMissing(varCnn) Then
'Set it to something
End If
End Function
 

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