Solved

Passing Null-parameters to User functions

Posted on 1998-11-10
4
186 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
  • 2
4 Comments
 
LVL 9

Expert Comment

by:perove
Comment Utility
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
Comment Utility
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 50 total points
Comment Utility
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
Comment Utility
To Jeroen,

As stated above, excellent because it works.
Thanks

Rene de Vriend

0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now