CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Nov 2005
    Posts
    75

    Question runtime error 3021

    Hey all guru

    I have a problem again. Why below code is doesnt work when i enter an ID which already exist in DB records.
    Code:
    Private Sub Command2_Click()
    Dim name As String
    Dim id As String
    id = Me.stuff_id
    
    If id = "" Then
          MsgBox " You should enter an ID "
    Else
          RS.Close
          RS.Open "Select * From table1 Where u_id='" & id & "'" , CN,  adOpenDynamic, adLockOptimistic
           If (RS.RecordCount > 0) Then
               Me.stuff_id = RS("u_id")
               Me.stuff_name = RS("u_name")
               shp_ctrl.Show
           Else
               MsgBox "No user id"
           End If
    End If
    Adodc1.Refresh
    End Sub
    if i make "if (RS.RecordCount < 0)" then it works but when enter a differnt ID number then have error.
    I am very confused and stuck here.
    Any help and idea please.

    Regards
    Last edited by jdavide; May 3rd, 2006 at 12:42 AM.

  2. #2
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: runtime error 3021

    Sometimes even when you have records in the recordset the recordcount property shows it as -1. This is because the provider does not support bookmarks or absolute position. You should make it a habit to check EOF & BOF rather than recordcount.

    In your case the recordset does not support recordcount property so you are getting -1 and thats why it works when you use less than sign. But even if there are no records in the recordset it will still return -1 as recordcount. So your code should check for EOF or BOF like this
    Code:
           If Not RS.BOF Then
               Me.stuff_id = RS("u_id")
               Me.stuff_name = RS("u_name")
               shp_ctrl.Show
           Else
               MsgBox "No user id"
           End If

  3. #3
    Join Date
    Nov 2005
    Posts
    75

    Re: runtime error 3021

    Ali u r Wonderfullllll... I love you.......... it works

  4. #4
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: runtime error 3021

    Quote Originally Posted by jdavide
    Ali u r Wonderfullllll... I love you.......... it works
    I love you too.

  5. #5
    Join Date
    Oct 2009
    Posts
    1

    Re: runtime error 3021

    hii ali.... I m getting the runtime error when interfacing 8051 with pc.. hav written code in vb6.. the error is either BOF or EOF is true, or the current record
    has been deleted. requested operation requires a current record..

    Plz help me with it... Its very urgent

  6. #6
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: runtime error 3021

    I think you'd do better starting your own post, along with sample code that you're having a problem with.
    Code:
    ' use Code Tags like this
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

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

Featured