Invalid Use of Null on Function parameters

  • Thread starter Thread starter Peter Hibbs
  • Start date Start date
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.
 
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
 
Back
Top