Jay
Jay

Reputation: 258

Run-time error '3021': Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record

Getting this error out of an old VB6 app that I've been presented with updating. So I got XP Mode up and running and VB6 installed and updated on it and I've added the menu option that was requested of me, but now I'm getting this error.

There are several examples of this error or similar here on SO and I looked through a bunch of them, but the circumstances aren't exactly the same and I'm still a pretty newbie developer and I just need help. I tested the query I wrote on our dev server and the VB syntax around it, that part is working fine. I think it has something to do with the result set logic near the end:

Private Sub FillDoor()

    Dim m_rsDoor As ADODB.Recordset

    cboDoorStyle.Clear

    Set m_rsDoor = conSQL.Execute("SELECT bpm.[Description] " & _
                                    "FROM tblBrandProductMaster bpm " & _
                                    "INNER JOIN tblDoorStyles ds " & _
                                        "ON ds.DoorStyleCode = bpm.Code " & _
                                    "INNER JOIN tblFamilyDoorStyles fds " & _
                                        "ON bpm.Code = fds.DoorStyleCode " & _
                                    "INNER JOIN tblFamilyLines fl " & _
                                        "ON fds.FamilyLineCode = fl.FamilyLineCode " & _
                                    "WHERE fl.FamilyLineCode = '" & strFamID & "' " & _
                                        "AND ds.DFFactive = 1 " & _
                                    "ORDER BY bpm.[Description] ASC")
    Do While Not m_rsDoor.EOF
        cboDoorStyle.AddItem m_rsDoor!Description
        m_rsDoor.MoveNext
    Loop
    Set m_rsDoor = Nothing

End Sub

****Edit: I'm using that query to populate a particular drop-down in the app and it is working on both on the SQL server and in the app.

Some of the examples on here use an If loop instead of a Do While Not, but they both get the same thing done and I don't think that's the issue. I also don't think that's the issue because I copied and pasted that part from another menu option on the app and that option works when I click it. It only throws the error when I choose the option I added.

Thanks, I appreciate any help anyone can offer.

Upvotes: 0

Views: 17485

Answers (2)

This error comes when there are no record in the record set. Please check if your query is correct and giving records.

Upvotes: 0

鄭有維
鄭有維

Reputation: 265

Modify like below code:

Private Sub FillDoor()

    Dim m_rsDoor As ADODB.Recordset
    Set m_rsDoor = New Recordset

    Dim ActiveConnection as String
    ActiveConnection = "XXXXXXXXXXX"

    Dim strSQL as String
    strSQL = "SELECT bpm.[Description] " & _
                                "FROM tblBrandProductMaster bpm " & _
                                "INNER JOIN tblDoorStyles ds " & _
                                    "ON ds.DoorStyleCode = bpm.Code " & _
                                "INNER JOIN tblFamilyDoorStyles fds " & _
                                    "ON bpm.Code = fds.DoorStyleCode " & _
                                "INNER JOIN tblFamilyLines fl " & _
                                    "ON fds.FamilyLineCode = fl.FamilyLineCode " & _
                                "WHERE fl.FamilyLineCode = '" & strFamID & "' " & _
                                    "AND ds.DFFactive = 1" & _
                                "ORDER BY bpm.[Description] ASC"

    m_rsDoor.open strSQL, ActiveConnection, adOpenStatic, adLockOptimistic

    Do While Not m_rsDoor.EOF
        cboDoorStyle.AddItem m_rsDoor!Description
        m_rsDoor.MoveNext
    Loop
    Set m_rsDoor = Nothing

End Sub

Upvotes: 0

Related Questions