?
Solved

Passing Null-parameters to User functions

Posted on 1998-11-10
4
Medium Priority
?
195 Views
Last Modified: 2008-02-26
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
0
Comment
Question by:nlnfmrvr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 9

Expert Comment

by:perove
ID: 1968129
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

0
 

Author Comment

by:nlnfmrvr
ID: 1968130
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
0
 
LVL 1

Accepted Solution

by:
JeroenW earned 200 total points
ID: 1968131
Dear nlnfmrvr,

You try to pass Null-values to input-arguments that do not accept Null-values. Access is not a very strong-typed tool, but you can't get away with everything.

Whenever you want to pass Null-values, be shure to declare the variable in the function-declaration as a Variant,
like:
Function StrTran(cFindIn As Variant, cFind As Variant, cRep As String, nReplaces As Integer) As String

Greetings,

Jeroen Westera
0
 

Author Comment

by:nlnfmrvr
ID: 1968132
To Jeroen,

As stated above, excellent because it works.
Thanks

Rene de Vriend

0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question