Help with NULL values 
Author Message
 Help with NULL values

Hi,
I'm a beginner in VB and need an answer to a simple question.
When i'm looping throudh a recordset and trying to find records
with NULL values in specific fields my program can't find them.

        Do Until MyRec.EOF
                if MyRec.Fields(2) = NULL Then
                        ...............
                        do some stuff
                        ...............
                End If
        Loop

Even when I'm in break mode and stepping trough code with [F8]
and when I move cursor over MyRec.Fields(2) (I love this new feature
in VB 5) it says 'MyRec.Fields(2)=Null', but program does not
'do some stuff' but jumps to End If .What is wrong with my code?!

Any help will be GREATLY appreciated.

Igor



Thu, 15 Jun 2000 03:00:00 GMT  
 Help with NULL values

The problem is that NULL is equal to nothing, including itself. (NULL means
unknown, so if this is confusing to you, you might want to contemplate what
it means to compare one unknown to another. Hopefully you'll arrive at the
conclusion that it doesn't mean much.)

To check for a NULL, use IsNull:

Do Until MyRec.EOF
    If IsNull(MyRec.Fields(2).Value) Then
         ...............
        do some stuff
        ...............
    End If
Loop

Quote:

>Hi,
>I'm a beginner in VB and need an answer to a simple question.
>When i'm looping throudh a recordset and trying to find records
>with NULL values in specific fields my program can't find them.

> Do Until MyRec.EOF
> if MyRec.Fields(2) = NULL Then
> ...............
> do some stuff
> ...............
> End If
> Loop

>Even when I'm in break mode and stepping trough code with [F8]
>and when I move cursor over MyRec.Fields(2) (I love this new feature
>in VB 5) it says 'MyRec.Fields(2)=Null', but program does not
>'do some stuff' but jumps to End If .What is wrong with my code?!

>Any help will be GREATLY appreciated.

>Igor




Thu, 15 Jun 2000 03:00:00 GMT  
 Help with NULL values

Hi,

I don't know if this is what you mean but what seems to be missing is the
statement MyRec.MoveNext
In your example you keep looking at the same record.....

Another thing is that there is, as far as I recall a function called Isnull.
Your program would then look something like this:

MyRec.Movefirst
Do Until MyRec.EOF
  if IsNull(MyRec.Fields(2))  Then
           ..............
          do some stuff
          ...............
     End If
  MyRec.MoveNext
Loop

greetings,

Roland


me know if it works!


Quote:
>Hi,
>I'm a beginner in VB and need an answer to a simple question.
>When i'm looping throudh a recordset and trying to find records
>with NULL values in specific fields my program can't find them.

> Do Until MyRec.EOF
> if MyRec.Fields(2) = NULL Then
> ...............
> do some stuff
> ...............
> End If
> Loop

>Even when I'm in break mode and stepping trough code with [F8]
>and when I move cursor over MyRec.Fields(2) (I love this new feature
>in VB 5) it says 'MyRec.Fields(2)=Null', but program does not
>'do some stuff' but jumps to End If .What is wrong with my code?!

>Any help will be GREATLY appreciated.

>Igor




Sun, 18 Jun 2000 03:00:00 GMT  
 Help with NULL values

In VB 4.0, there is an ISNULL function intended to explicitely check values on a
NULL value. I think it's the same in VB 5, isn't it ?

Just try 'IF ISNULL(expr) ...' !



Sun, 18 Jun 2000 03:00:00 GMT  
 Help with NULL values



Quote:

>    Do Until MyRec.EOF
>            if MyRec.Fields(2) = NULL Then
>                    ...............
>                    do some stuff
>                    ...............
>            End If
>    Loop

Try

                if IsNull(MyRec.Fields(2)) Then

--------------------------------------------------------------------
Fulvio Senore

Eliminate "zz" dall'indirizzo e-mail per scrivermi (spammers...)
Remove "zz" from e-mail address to write me (spammers...)
--------------------------------------------------------------------



Mon, 19 Jun 2000 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Help: Inserting null values into Jet database using ADO

2. HELP: SQL + Null value

3. NULL Values in SQL Queries - HELP HELP

4. How can I pass NULL value to WinAPI which is expecting a NULL pointer

5. Sending null strings and NULL values

6. adodb connection to excel: recordset.fields(i).value=null for fields with numeric value

7. adodb connection to excel: recordset.fields(i).value=null for fields with numeric value

8. doesn't recognize Null value from a field value

9. adodb connection to excel: recordset.fields(i).value=null for fields with numeric value

10. Checking for Null values - Help

11. Parameter Query/Null Value help

12. Paramter Query/Null Value help

 

 
Powered by phpBB® Forum Software