Putting Null Value in String Variable

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?
 
K

Ken Snell [MVP]

String variables cannot hold Null value. So use Nz to convert it to empty
string:

MyStringVariable = Nz(Me.TextBoxName.Value, "")
 
D

Dirk Goldgar

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.
 
D

Douglas J. Steele

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
 

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