Results 1 to 4 of 4

Thread: Invalid use of Null !

  1. #1

    Thread Starter
    Member Alankar's Avatar
    Join Date
    Jun 2005
    Location
    Ghaziabad, India
    Posts
    40

    Unhappy Invalid use of Null !

    Hi All,

    I am using following code in VBA to get some records (in my case it is a single record). On Message box line it shows "Invalid use of Null" error, How could I prevent this. Is there any method to know any record is there in recordset or not. As if no record is returned then I want to print "No Match".

    ***************CODE******************************

    Set DB = CurrentDb()

    'Get Total Actual Project time from TimeSheet
    Actprj = "SELECT (Int(CSng(Sum([Duration])))*24)+Format(Sum([Duration]),'hh') & ' : ' & Format(Sum([Duration]),'nn') AS Expr1" _
    & " FROM tbTimeSheet HAVING ((tbTimeSheet.PrjID)='" & Form_TmpInfoPrj.cmbPrj.Value & "')"
    Set Rst = DB.OpenRecordset(Actprj)
    msgbox Rst.Field(0).value

    ************************CODE***************************

    Regards,
    Alankar
    The rest of mind is not in rest, It rests in rest.

  2. #2
    Addicted Member
    Join Date
    Jun 2005
    Posts
    139

    Re: Invalid use of Null !

    It is always a good practice to check if any records are there in the recordset. The way to do this is

    if Rst.Eof and Rst.Bof then
    msgbox "No Records returned"
    else
    msgbox Rst.Field(0).Value
    end if

  3. #3

    Thread Starter
    Member Alankar's Avatar
    Join Date
    Jun 2005
    Location
    Ghaziabad, India
    Posts
    40

    Re: Invalid use of Null !

    Please see my following thread also !

    Table update problem !
    The rest of mind is not in rest, It rests in rest.

  4. #4
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Invalid use of Null !

    In Access:
    Nz function (very useful) takes two parameters, the first is the variable you are checking, the second is the default value should the first be null.

    In VB/Access:
    Isnull function - example : debug.print isnull(rst(0))
    Returns true if the variable is null, and false if not.

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width