Passing Null As Parameter

homer2002

Registered User.
Local time
Today, 06:15
Joined
Aug 27, 2002
Messages
152
Still having Null trouble

Can anyone get this to work.
I'm having a stupid day :-)
(obviously i will be passing variables into the function in reality)
________________________________

Function testnull(sString As String) As String
If IsNull(sString) Then sString = ""
testnull = sstring
End Function


Private Sub Command0_Click()
msgbox testnull(Null)
End Sub

_____________________________


Access wont allow me to pass Null into the function.

cheers Homer
 
Why are you trying to pass a Null value?
 
I'm not trying to pass a null value

i'm trying to stop a function crashing when I try to pass in
a string that may or may not contain a null value.
 
Wrong order, then.

You should check if the string is Null before you send it.
 
Also, rather than use "" for assigning a null string you'd be better to use the Access constant provided: vbNullString.
 
Oh right I gotya.


I thought i would be able to handle it within the function.

cheers
 
homer2002 said:
I thought i would be able to handle it within the function.

No, because the String parameter expects a string value. The error is triggered when you try to send the Null data to a string data type.
 
I guess what is confusing people is why you are writing your own function to change nulls to zero-length strings. There is a VBA function that will change nulls to whatever value you choose. Nz(YourNumericField, 0) or Nz(YourTextField, "N/A") You can use whatever you want as the second argument provided it is compatable with the field type.
 

Users who are viewing this thread

Back
Top Bottom