Putting Null Value in String Variable

  • Thread starter Thread starter Gibson
  • Start date Start date
G

Gibson

I have a control in a table that I want to puts is value into a string
variable for testing purposes. The data type of the table control is Text
so sometimes it is null. If I try to load the null value into the String
variable I get the dreaded Invalid Use of Null error. Is there a way to put
the null value into a string variable?
 
String variables cannot hold Null value. So use Nz to convert it to empty
string:

MyStringVariable = Nz(Me.TextBoxName.Value, "")
 
Gibson said:
I have a control in a table that I want to puts is value into a string
variable for testing purposes. The data type of the table control is
Text so sometimes it is null. If I try to load the null value into
the String variable I get the dreaded Invalid Use of Null error. Is
there a way to put the null value into a string variable?

Not as a Null. You could either put the word "Null" there, or you could
put a zero-length string there. But only a Variant variable can hold a
Null value.
 
No, there isn't. The only variable type that can hold a Null value is a
Variant.

What you can do is concatenate a zero-length string ("") to the value you're
trying to assign to the string:

strValue = Me.MyPossibleNullValue & ""

or

strValue = Me.MyPossibleNullValue & vbNullString
 
Back
Top