Link to home
Start Free TrialLog in
Avatar of leenapedenekar
leenapedenekar

asked on

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 “”

Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

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
ASKER CERTIFIED SOLUTION
Avatar of Colosseo
Colosseo
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Yes, Colloseo, you are right. A senior moment. I'm afraid.
Avatar of JR2003
JR2003

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