Solved

Passing Null-parameters to User functions

Posted on 1998-11-10
4
189 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 50 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
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…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

803 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