Checking optional arguments for null

J

jpt

How can I check an optional function argument (type is
DAO.recordset) for null or check to see if it has been
passed before performing operations on it? I wanted to set
a boolean variable to Isnull(rstSrc) but that doesn't work.

MyFunction (strSRC as string, Optional rstSrc as
dao.recordset)

What should I use?
 
M

Marshall Barton

jpt said:
How can I check an optional function argument (type is
DAO.recordset) for null or check to see if it has been
passed before performing operations on it? I wanted to set
a boolean variable to Isnull(rstSrc) but that doesn't work.

MyFunction (strSRC as string, Optional rstSrc as
dao.recordset)

What should I use?

The IsMissing function can be used if you make the argument
a Variant. For an argument that's an object, I don't know,
but maybe
If rstSrc Is Nothing Then
will do what you want.
 
H

Heiko

Public Sub demoCall()
Dim rsDst As DAO.Recordset
Dim strDst As String
Dim varRet
strDst = "demo"
Set rsDst = CurrentDb.OpenRecordset("demo")
varRet = myFunction(strDst)
varRet = myFunction(strDst, rsDst)
End Sub

Public Function myFunction(strSrc As String, Optional rsSrc As
DAO.Recordset)
If rsSrc Is Nothing Then
myFunction = False
Else
myFunction = rsSrc.Fields.Count
End If
End Function
 
J

jpt

Perfect...
Thanks.

Can you answer one other question?
Why would you explicitly declare and set your database
when opening a recordset instead of using CurrentDB
Set rstTmp=currentdb.openrecordset.....
Are there any drawbacks to doing it the second way?
Thanks,
JPT
 
H

Heiko

Hello again
that was snip from an excisting Database, you can use any predeclared
Dao.Recordset and you don't have to use Set ...
But if in a function like that the Recordset (given by Ref) can
possibly be changed and in the calling sub maybe i have to check
something.

Heiko
:)
 

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