Solved

if... else don't work?

Posted on 2000-03-07
3
144 Views
Last Modified: 2010-05-02
Is here something wrong:

Do While Data1.Recordset.EOF <> True
  If Data1.Recordset(1).Value = Null Then
    List1.AddItem Data1.Recordset(0)
  Else
    List1.AddItem Data1.Recordset(1)
  End If
   
  Data1.Recordset.MoveNext
Loop

Even if there is NULL in Data1.Recordset(1).Value, List1.AddItem Data1.Recordset(0) never happen?
0
Comment
Question by:majala
3 Comments
 
LVL 2

Accepted Solution

by:
damienm earned 50 total points
ID: 2591136
Use

If IsNull(Data1.Recordset(1).Value) then

instead of Data1.Recordset(1).Value = Null
0
 
LVL 4

Expert Comment

by:wesleystewart
ID: 2591782
damienm is correct.  You can't test for null with "= Null" because the right side of the equation will ALWAYS evaluate to False.

Wes
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2592538
Assuming Data1.Recordset(1).Value is a String.. A better way to do this test (and more efficient) is to just test the length of it.. <smile>

If Len(Data1.Recordset(1).Value) > 0 _
Then
  List1.AddItem Data1.Recordset(1)
Else
  List1.AddItem Data1.Recordset(0)
End If
     
 
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

821 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