Solved

null value

Posted on 2004-08-21
6
169 Views
Last Modified: 2010-05-02
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 “”

0
Comment
Question by:leenapedenekar
6 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 11858012
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
 
LVL 15

Accepted Solution

by:
Colosseo earned 25 total points
ID: 11858043
Graham should that not be

If Not IsNull(MyVariable) Then
...
End If
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 11858062
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
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 11860282
Yes, Colloseo, you are right. A senior moment. I'm afraid.
0
 
LVL 18

Expert Comment

by:JR2003
ID: 11863545
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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now