Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Passing Null-parameters to User functions

Posted on 1998-11-10
4
Medium Priority
?
196 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
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
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…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

885 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