Having Null Trouble

homer2002

Registered User.
Local time
Today, 05:35
Joined
Aug 27, 2002
Messages
152
Having Null Trouble :-)

I am trying to create a function that will pass out either....

The string that is passed in
or
"Null" (as a string)

problem is, i am having trouble passing Null into a function
if I try to pass in a Null String access really doesnt like it :0(

example
____________________________________

Function passString(Optional InputString As String) As String
If Len(InputString) <= 0 Then
passString = "Null" 'Supposed to be like this (NOT PassString = Null)
Else
passtring = "'" & InputString & "'"
End Function

rivate sub ATest()
Dim MyString as string
MyString = null
msgbox MyString
end sub
_____________________________________


Can anyone help, this shouldn't be this difficult. I must be losing it







____________________________________
 
Code:
Private Sub ATest()
    Dim MyString As String
    MyString = vbNullString
    MsgBox MyString
End Sub
 
Re: Having Null Trouble :-)

Code:
Function passString(Optional InputString As String) As String
    If Len(InputString) <> 0 Then
        passtring = "'" & InputString & "'"
    Else
        passString = "Null"
    End If
End Function

Why are you putting apostrophes around the value of InputString?
 
I have to pass "Null" into the String as I am using it to create some SQL for a docmd.runSQL statement.

The field comes from a list box (That could be set to Null)

The SQL would have to read somthing like this

SELECT * FROM tblAccount WHERE Accountnumber = '123456789'

or if the Accountnumber (String) being passed into the SQL is Null

then I will need to create a string like this

SELECT * FROM tblAccount WHERE Account = Null

:-)

Its a bit more complicated than that, but you get the idea.

:-)
 

Users who are viewing this thread

Back
Top Bottom