Results 1 to 7 of 7

Thread: Runtime Error 3021

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2005
    Location
    Toronto, Canada
    Posts
    357

    Runtime Error 3021

    Hey all,
    I am testing a http link search robot I created. I am getting a Runtime Error 3021 which I don't know a lot about. I was hoping some of you could help.

    The message I get is:

    Run-time error '3021':

    Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.

    When I click on the Debug button, it gives me the following statement to fix:

    VB Code:
    1. buf = rsURL!URL & " (" & rsURL!relevance & ")"

    Thank you for your help in advance.

    Khanjan
    Hey... If you found this post helpful please rate it.

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Runtime Error 3021

    Well, there is nothing wrong with that line of code by itself. However if you want to get the value of a recordset field it must contain something. According to the error message the recordset is either empty or not currently pointing to any record. Normally before you read from a recordset you would first check that the EOF (End Of File) property isn't true. Can you show a little bit more of your code?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2005
    Location
    Toronto, Canada
    Posts
    357

    Re: Runtime Error 3021

    Here is my program.
    Anyways sorry its time for me to go to bed. I will reply again tomorrow.

    Khanjan
    Attached Files Attached Files
    Hey... If you found this post helpful please rate it.

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

    Re: Runtime Error 3021

    Post it as a .zip file. Many people have no way of opening a .rar file. It would also help you to get an answer if you indicated which form the error occurred in (and which sub or function).
    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

  5. #5
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Runtime Error 3021

    Actually it would be enough if you posted the code in the procedure the error line is in.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2005
    Location
    Toronto, Canada
    Posts
    357

    Re: Runtime Error 3021

    Hi,
    Here is the code.

    VB Code:
    1. Private Sub Form_Load()
    2.  
    3. Dim strConnect As String
    4. Dim buf As String
    5. Dim SQLString As String
    6.  
    7. strConnect = "Provider=Microsoft.Jet.OLEDB.3.51;"
    8. strConnect = strConnect & "Persist Security Info=False;"
    9. strConnect = strConnect & "Data Source = " & gDataFileName
    10.  
    11. Set cnLinks = New ADODB.Connection
    12. Set rsURL = New ADODB.Recordset
    13.  
    14. cnLinks.ConnectionString = strConnect
    15. cnLinks.ConnectionTimeout = 10
    16. cnLinks.CursorLocation = adUseNone
    17. cnLinks.Open
    18.  
    19. SQLString = "Select * from links where relevance > 0 "
    20. SQLString = SQLString & "order by relevance"
    21.  
    22. rsURL.Open SQLString, cnLinks, adOpenDynamic, adLockOptimistic, adCmdText
    23.  
    24. Do
    25.  
    26.     buf = rsURL!URL & " (" & rsURL!relevance & ")"
    27.     lstReport.AddItem buf
    28.     rsURL.MoveNext
    29.    
    30. Loop While Not rsURL.EOF
    31.  
    32. End Sub

    And I have also attached the program in .zip format.

    Khanjan
    Attached Files Attached Files
    Hey... If you found this post helpful please rate it.

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Runtime Error 3021

    Your loop keeps going until you reach the end of the recordset (after all the records).. but it seems that you are already at the end of the recordset before the loop starts - which is why there is no data to be retrieved by that line (and hence the error).

    You need to basically not let the loop run if there is no data, which can be done by:
    a) Putting an IF block around the loop. eg:
    VB Code:
    1. If Not rsURL.EOF Then
    2.   Do
    3.     ...
    4.   Loop While Not rsURL.EOF
    5. End If
    or b) Changing the structure of the loop slightly (so it is never entered if there is no data - but still exits at the end of the data), eg:
    VB Code:
    1. Do While Not rsURL.EOF
    2.   ...
    3. Loop

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