With the Function statement as you suggested:
Code:
Public Function eBudAcctBal(TableName As String, Optional ID As Variant, Optional Dte As Variant) As Currency
The use of "IsNull" will result in a code path taken where the "missing" parameter will get referenced "by name" resulting in datatype error. What is required to properly test parameters is "IsMissing". The following code block processes perfectly. (BTW, the code is preparing a SELECT string in preparation for updating a QueryDefs so I can get JET to do all the needed calculations work.)
Code:
If IsMissing(ID) And IsMissing(Dte) Then
strQuery = strQuery & QALL
Else
If Not IsMissing(ID) And IsMissing(Dte) Then
strQuery = strQuery & QID
strQuery = Replace(strQuery, "IDExp", ID)
Else
If IsMissing(ID) And Not IsMissing(Dte) Then
strQuery = strQuery & QAllDated
strQuery = Replace(strQuery, "dteExp", Dte)
Else
If Not IsMissing(ID) And Not IsMissing(Dte) Then
strQuery = strQuery & QIdDated
strQuery = Replace(strQuery, "IDExp", ID)
strQuery = Replace(strQuery, "dteExp", Dte)
End If
End If
End If
End If