null value

I have a application in visual basic with access as backend
In the form if I take value for any text box and save it in the database
And next time while editing if I try to make it null and save it
Next time I get the error invalid use of null although I have checked for no values required
In the access and default value to “”

leenapedenekarAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
ColosseoConnect With a Mentor Commented:
Graham should that not be

If Not IsNull(MyVariable) Then
...
End If
0
 
GrahamSkanRetiredCommented:
It sounds as if you are succcessfully reading a null value from the database and then trying to do something with it in VB that cannot be done with a Null.
You'll need to test for null before you use it.

If Not MyVariable Is Null Then
...
End If
0
 
Ryan ChongCommented:
also can try like below, if you want to retrieve values from your db to textbox:

text1.text = "" & Rs("myfield")

this will make you ease and no need to check whether the value return is null or not.
0
 
GrahamSkanRetiredCommented:
Yes, Colloseo, you are right. A senior moment. I'm afraid.
0
 
JR2003Commented:
leenapedenekar

ryancys solution is probably the neatest for any text field.
Anytime you receive some text from the database that could possibly be null, just add & "" on the end of the line.

e.g. Text1.Text = Rs("myfield").Value & ""  

For date and numeric fields that can possibly be null just use the IsNull function

If IsNull(Rs("myfield").Value) Then
...
Else
...
End IF

JR
0
All Courses

From novice to tech pro — start learning today.