Results 1 to 6 of 6

Thread: Empty Recordset [Resolved]

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2003
    Location
    Georgia
    Posts
    32

    Empty Recordset [Resolved]

    I added a record to the table and I am still getting empty recordset. I have two tables:

    tblClassification - id, classification
    tblSnipplets - id, dateadded, classification, code, title

    I am getting the following error:
    Run-Time Error '3021'. Either BOF or EOF is True, or the current record has been deleted.


    Code:
    Private Sub initializeTree()
    
    tvwItems.ImageList = imgList
        
        Dim nodClass As Node
        Dim nodTitle As Node
        
        tvwItems.LineStyle = tvwRootLines
        tvwItems.Nodes.Clear
        
        'Opens the recordset for Class
        Set rsClass = New ADODB.Recordset
        strSQLClass = "SELECT id, classification FROM tblClassification ORDER BY classification"
        rsClass.Open strSQLClass, conTree, adOpenStatic, adLockOptimistic
        
        'set node for treeview
        If rsClass.RecordCount > 0 Then
            While Not rsClass.EOF
                Set nodClass = tvwItems.Nodes.Add(, , (rsClass.Fields("classification")), (rsClass.Fields("classification")), 1)
                rsClass.MoveNext
                DoEvents
            Wend
        End If
        
        'Opens the recordset for Title
        Set rsTitle = New ADODB.Recordset
        strSQLTitle = "SELECT title, classification, code, dateadded FROM tblSnipplets WHERE classification LIKE '" & (rsClass.Fields("classification")) & "%'"
        rsTitle.Open strSQLTitle, conTree, adOpenStatic, adLockOptimistic
        
        'set node for treeview
        If rsTitle.RecordCount > 0 Then
            While Not rsTitle.EOF
                Set nodTitle = tvwItems.Nodes.Add((rsClass.Fields("classification")), tvwChild, (rsTitle.Fields("title")), (rsTitle.Fields("title")), 2)
                rsTitle.MoveNext
                DoEvents
            Wend
        End If
        
    End Sub
    Last edited by odamsr; Apr 6th, 2004 at 04:44 PM.

  2. #2
    Fanatic Member ahara's Avatar
    Join Date
    Nov 2003
    Location
    Toronto
    Posts
    531
    Looks like the error is coming from the record set rsClass which you advance until the EOF, then try to pull a field from it in the latter part of your code.
    "Knowledge is gained when different people look at the same information in different ways"

    - Louis Pasteur

  3. #3
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    Whether rsClass contains 0, 100 or 1,000,000 records, by the time the following code is executed, rsClass.EOF will be True.

    strSQLTitle = "SELECT title, classification, code, dateadded FROM tblSnipplets WHERE classification LIKE '" & (rsClass.Fields("classification")) & "%'"

    You will need to store the classification value in a variable before this line executes. Which one depends on your needs?

    Also, base on your posted code, if rsClass.RecordCount is 0 then you do not want to execute the code for rsTitle, but simply drop out of the sub

  4. #4

    Thread Starter
    Member
    Join Date
    Jun 2003
    Location
    Georgia
    Posts
    32
    I changed my code to the following and now it is not showing all of the classifications. I am only getting the first one.

    Code:
    'set node for treeview
     Set nodClass = tvwItems.Nodes.Add(, , (rsClass.Fields("classification")), (rsClass.Fields("classification")), 1)

  5. #5
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    ??? what has changed. That line is the same as your old code.

    Let me know if this is correct - you are trying to
    Add a Root node for every Classification
    Add child nodes for every Title in the Classification.

    You should execute your rsTitle query for each row in your rsClass recordset.

    VB Code:
    1. Private Sub initializeTree()
    2.     tvwItems.ImageList = imgList
    3.    
    4.     Dim nodClass As Node
    5.     Dim nodTitle As Node
    6.    
    7.     tvwItems.LineStyle = tvwRootLines
    8.     tvwItems.Nodes.Clear
    9.    
    10.     'Initialize the recordsets
    11.     Set rsClass = New ADODB.Recordset
    12.     Set rsTitle = New ADODB.Recordset
    13.  
    14.     'Open the Class recordset
    15.     strSQLClass = "SELECT id, classification FROM tblClassification ORDER BY classification"
    16.     rsClass.Open strSQLClass, conTree, adOpenStatic, adLockOptimistic
    17.    
    18.     'set node for treeview
    19.     If rsClass.RecordCount > 0 Then
    20.         While Not rsClass.EOF
    21.             Set nodClass = tvwItems.Nodes.Add(, , (rsClass.Fields("classification")), (rsClass.Fields("classification")), 1)
    22.  
    23.             'Opens the recordset for Title
    24.             strSQLTitle = "SELECT title, classification, code, dateadded FROM tblSnipplets WHERE classification LIKE '" & (rsClass.Fields("classification")) & "%'"
    25.             rsTitle.Open strSQLTitle, conTree, adOpenStatic, adLockOptimistic
    26.            
    27.             'set node for treeview
    28.             If rsTitle.RecordCount > 0 Then
    29.                 While Not rsTitle.EOF
    30.                     Set nodTitle = tvwItems.Nodes.Add((rsClass.Fields("classification")), tvwChild, (rsTitle.Fields("title")), (rsTitle.Fields("title")), 2)
    31.                     rsTitle.MoveNext
    32.                     DoEvents
    33.                 Wend
    34.             End If
    35.             rsTitle.Close
    36.            
    37.             rsClass.MoveNext
    38.             DoEvents
    39.         Wend
    40.     End If
    41. End Sub

    You can probably optimize this by using a one recordset. Your existing sql statements can be combined using a Left Join. Then you only need to loop through a single recordset.

  6. #6

    Thread Starter
    Member
    Join Date
    Jun 2003
    Location
    Georgia
    Posts
    32
    That was what I was trying to do. Thanks for you help. The code worked.

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