Invalid Use of Null on Function parameters

P

Peter Hibbs

I have a general Function routine which has in-line parameters
something like this :-

'------------------------------------------------------------------
Public Function SendData(strName As String) As String

Dim X As String

X = strName
.....

End Function
'------------------------------------------------------------------

I call the function like so :-

Z = SendData(Me.txtName)

where txtName is Text control on a form. The problem is that if
txtName is blank (i.e. Null) the call fails with :-

Run-time error '94'
Invalid use of Null

I can fix the error by using... SendData(Nz(Me.txtName))

but if the function is called a large number of times it is a bit
inconvenient having to remember to add the Nz() every time. What I
would like to do is add the Nz() code within the function, something
like :-

X = Nz(strName)

but this does not work. Is there any way to move the Nz bit into the
function code?

Peter Hibbs.
 
D

Douglas J. Steele

Public Function SendData(strName As Variant) As String

Dim X As String

If IsNull(strName) Then
SendData = vbNullString
Else
X = strName
.....
End If

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top