Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why this If condition don't works? 1

Status
Not open for further replies.

Lreader

Technical User
Jul 27, 2000
13
CA
I am quite a beginner in programming. I have some code to put in an Access module:

I don't know why VB don't go into this condition when it is true:

Dim Test1 as integer
Dim Test2 as integer

Test1 = Null

If Test1 = Null Then
Test2 = aValue
End if


It jump to End if. Is there an other way to write my condition. I really need to test a variable with Null value to do something else.

 
I'm not sure but maybe this:

if test1 = vbnull then

But remeber that since you delcared it right there as interger I think it defaults to 0.
Brad,
Hey! email me any time! Bradsvb@yahoo.com
 
You cannot assign an integer variable to NULL. By default an integer is 0. The proper way to test for NULL is with the isNull() function i.e.

If isNull(MyVariable) Then

This won't work here however.
 
try this

Dim Test1 as integer


Test1=0

If Test1 = 0 Then

Msgbox " The value is zero"

End if
:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top