Checking optional arguments for null

  • Thread starter Thread starter jpt
  • Start date Start date
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?
 
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.
 
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
 
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
 
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
:-)
 
Back
Top