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
Thanks and regards,
Rene
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
To Jeroen,
As stated above, excellent because it works.
Thanks
Rene de Vriend
As stated above, excellent because it works.
Thanks
Rene de Vriend
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