IsNull is not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Shelly Bay
    New Member
    • Jun 2010
    • 2

    #1

    IsNull is not working

    Apologies. I am not an experience programmer so I suspect this is a very simple problem. I am trying to get a piece of code in VB for Access to recognise a null set but unfortunately the test is returning False for IsNull even though I know no records have been found in the table, eg.

    Code:
    strFeriados = "SELECT tlkpFeriados.* FROM tlkpFeriados WHERE ((tlkpFeriados.Fecha)=#" & CDate(MyDate)& "#);"                                          
                                
    If IsNull(strFeriados) = False Then
    In other words, there is no record in tlkpFeriados which matches the value of MyDate that I am passing to the sql string yet IsNull is still returning False.

    Is the test affected by the format of the date value passed to the string?

    Please could someone advice me?

    Many thanks in advance!

    SB
  • vb5prgrmr
    Recognized Expert Contributor
    • Oct 2009
    • 305

    #2
    Okay, looks like a common mistake you are making...

    What you want to do it to test the date and just the date. You do not want to test the string variable because it will always return false as you are doing something like...
    Code:
    strSQL = "Test " & vbNull & "Line"
    and thus the string is not empty (IsEmpty) either as it contains a string value...

    Now, from the looks of it you are actually wanting to test the results returned from executing your query to see if you have any records, which you can do by testing the recordcount property, the bof, and eof properties...
    Code:
    if Rs.RecordCount <> 0 And Rs.EOF = False And Rs.BOF = False Then
      'have records
    Else
      'No Records
    End If


    Good Luck

    Comment

    • QVeen72
      Recognized Expert Top Contributor
      • Oct 2006
      • 1445

      #3
      Hi,

      You Need to open the recordset ... and check results of recordset

      Comment

      • Shelly Bay
        New Member
        • Jun 2010
        • 2

        #4
        That works! Many thanks.

        Comment

        Working...