Link to home
Start Free TrialLog in
Avatar of nlnfmrvr
nlnfmrvr

asked on

Passing Null-parameters to User functions

If I pass parameters with a null value to my own build userfunction, the function is not started at all. This means that a check for null value must happen before entering the function. Is this a standard behavior of MS-Access, and if yes, can I prevent this, so that I can do the check within the function itself.

Thanks and regards,
Rene
Avatar of perove
perove
Flag of Norway image

Use the optional argument when declaring the function, the do the test within the function. See help on optional for details, be sure to put the optional parameters in the end
ex:
function Bullshit(a as integer, optional b as variant)
if insnull(b) then
   msgbox "B is null and perove is a nice person)
end if
end  function

sub TestBullShit
dim b as variant
a = 2
s= bullshit(a,b)
end sub

let me know

perove

Avatar of nlnfmrvr
nlnfmrvr

ASKER

Sorry Perove, but it doesn't work.

This is my function :

Function StrTran(cFindIn As String, cFind As String, cRep As String, nReplaces As Integer) As String
'
'Search and replace characters within a string
'
    Dim loop1 As Boolean, cResult As String, x As Integer, nPos As Integer
       
    If Not IsNull(cFindIn) And Not IsNull(cFind) Then
        loop1 = True
        Do While loop1
            nPos = InStr(1, cFindIn, cFind)
            If nPos = 0 Then
                loop1 = False
            Else
                cFindIn = Left(cFindIn, nPos - 1) + cRep + Mid(cFindIn, nPos + Len(cFind))
                x = x + 1
                loop1 = IIf(x = nReplaces And nReplaces <> 0, False, loop1)
            End If
        Loop
     End If
    StrTran = cFindIn
End Function

Even when I swap the parameters and assure that the first one is always a valid value (being not null), the result is still #error.

Any other idea.
Cheers,
Rene
ASKER CERTIFIED SOLUTION
Avatar of JeroenW
JeroenW

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
To Jeroen,

As stated above, excellent because it works.
Thanks

Rene de Vriend