Solved

null value

Posted on 2004-08-21
6
171 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VBA Excel: Copy Data from one workbook to another v6 csv extension 15 77
Replace Formatted Numbers with text 9 61
VB error "Type mismatch" 2 49
How to debug this code 7 56
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

910 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

22 Experts available now in Live!

Get 1:1 Help Now