Results 1 to 7 of 7

Thread: [RESOLVED] Quick question regarding empty recordsets

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Posts
    245

    Resolved [RESOLVED] Quick question regarding empty recordsets

    hi all

    I have a recordset that sometimes will pull no data due to changes made to the database tables throughout the useage of the program. My question is this, what is the syntax to handle recordsets when they come up with no info?

    i have tried things like this:

    VB Code:
    1. If rs("")<>"" then do something

    and

    VB Code:
    1. IF isNull(rs("")) then do something

    how would i word the part concerning the rs on order to satisfy the IF statement?

    With both examples i get a
    "Item cannot be found in the collection corresponding to the requested name or ordinal."
    thanks alot
    tibor

  2. #2
    Hyperactive Member
    Join Date
    Apr 2004
    Posts
    342

    Re: Quick question regarding empty recordsets

    VB Code:
    1. If rs.RecordCount = 0 Then
    2.  
    3.   ' No Rows Returned '
    4.  
    5. End If

  3. #3
    Hyperactive Member
    Join Date
    Apr 2004
    Posts
    342

    Re: Quick question regarding empty recordsets

    You would need a valid field name between the "".

    VB Code:
    1. If rs.Fields("FieldName").Value & "" = "" Then
    2.  
    3.   ' All this really tells you is that "FieldName" is Null or Blank..... '
    4.   ' Record Count is One Way '
    5.  
    6. End If

    VB Code:
    1. If rs.Eof = True  Then
    2.  
    3.   ' Also means no records (right after the select) '
    4.  
    5. End If

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Posts
    245

    Re: Quick question regarding empty recordsets

    ok great. thanks so much!

    the Rs.EOF took care of it. The rowcount always came back as -1. Why would it ever come back as a neg?

    tibor

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Quick question regarding empty recordsets

    Quote Originally Posted by tibor
    the Rs.EOF took care of it. The rowcount always came back as -1. Why would it ever come back as a neg?
    That is a built in "featue" of an ado serverside recordset and when the CursorType is adOpenForwardonly or adOpenDynamic.

    Use either adOpenKeyset or adOpenStatic as the CursorType for server side cursors or use a client side cursor. Client side cursors use only adOpenStatic for CursorTypes regardless of which CursorType you select.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Posts
    245

    Re: [RESOLVED] Quick question regarding empty recordsets

    Ok, sweet. thanks. Now its something I know.. haha.

    tibor

  7. #7
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: [RESOLVED] Quick question regarding empty recordsets

    If you set rs.CursorLocation = adUseClient (before you open the recordset) you'll get back valid rowcounts.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

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