Link to home
Create AccountLog in
Visual Basic Classic

Visual Basic Classic

--

Questions

--

Followers

Top Experts

Avatar of ISC
ISC

VB6 and Checking for Null
Hi,
I am using VB6 and in the code I execute a SQL query that returns a set of records.
I need to check 2 columns in the recordset for being Null.
When I use IsNull the application throws an error "Invalid Use Of Null" and jumps to my local error handler when I reference other columns that are not Null in the recordset...
How can I get around this...?
Thanks Ian Carrick

 If (IsNull(l_BankAccount.Recordset.Fields("BANKCODE")) = True) Or _
                       (IsNull(l_BankAccount.Recordset.Fields("BANKACCOUNT")) = True) Then
                         
                        If ((CInt(l_BankAccount.Recordset.Fields("STATUSCODE")) = 1) And _
                           (UCase(l_BankAccount.Recordset.Fields("INTERESTINDICATOR")) = "Y") And _
                           (UCase(l_BankAccount.Recordset.Fields("OVERDRAFTINDICATOR")) = "Y")) Then


                     End If
             
 End If






Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]Guy Hengel [angelIII / a3]🇱🇺

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Avatar of CWS (haripriya)CWS (haripriya)🇮🇳

I think you have to reverse your IF condition...instead of "IsNull" use "Not IsNull" or like this:

If (IsNull(l_BankAccount.Recordset.Fields("BANKCODE")) = False) Or _
                       (IsNull(l_BankAccount.Recordset.Fields("BANKACCOUNT")) = False) Then
                         
                        If ((CInt(l_BankAccount.Recordset.Fields("STATUSCODE")) = 1) And _
                           (UCase(l_BankAccount.Recordset.Fields("INTERESTINDICATOR")) = "Y") And _
                           (UCase(l_BankAccount.Recordset.Fields("OVERDRAFTINDICATOR")) = "Y")) Then


                     End If
             
 End If

Avatar of mdouganmdougan🇺🇸

I think Angel's got it, but there is another workaround in VB for null values, and that is to concatenate an empty string to the field value and check for an empty string.  But that only works if you don't have to distinguish between NULL values and blank values.

If (l_BankAccount.Recordset.Fields("BANKCODE").value & "" = "") Or _

or try

If ((IsNull(l_BankAccount.Recordset.Fields("BANKCODE")) = True) Or _
                       (IsNull(l_BankAccount.Recordset.Fields("BANKACCOUNT")) = True)) Then

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.

Visual Basic Classic

Visual Basic Classic

--

Questions

--

Followers

Top Experts

Visual Basic is Microsoft’s event-driven programming language and integrated development environment (IDE) for its Component Object Model (COM) programming model. It is relatively easy to learn and use because of its graphical development features and BASIC heritage. It has been replaced with VB.NET, and is very similar to VBA (Visual Basic for Applications), the programming language for the Microsoft Office product line.