Run time error '3021' message

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ovees
    New Member
    • Dec 2009
    • 2

    Run time error '3021' message

    Am currently working with VB 6.0 and Win7 OS. My application is linked with Microsoft Access 2007 (2002-2003 file format) database and whenever I want to update a record in a table from the Access database the project will display a message "Run-time error '3021' Either BOF or EOF is true, or the current record has been deleted. Requested operation requires a current record."
    The challenge I have is on line 10 that's where my project halts. Would there be any approach I can use to continue with my project. Below is the code for update procedure.

    Code:
    Private Sub updateButton_Click()
       If rs.State = adStateOpen Then rs.Close
       Con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\NDASS.mdb"
       rs.Open "SELECT*FROM Details where RegNumber='" & txtSearch.Text & "'", _
                    Con, adOpenKeyset, adLockPessimistic
       If rs.BOF Or rs.EOF = True Then
          rs.update
          txtRegNo.Text = rs![RegNumber]
          txtSurname.Text = rs!Surname
          txtMiddleName.Text = rs!MiddleName
          txtOtherName.Text = rs!Othernames
          cboDOB1.Text = rs!DOB1
          cboDOB2.Text = rs!DOB2
          cboDOB3.Text = rs!DOB3
          imgPassport.Picture = LoadPicture(rs!Passport)
          '
          txtCivilianPersonnelName.Text = rs!CivilianPersonnelName
          txtOffBusAddress.Text = rs!civilianOfficeBusinessAddress
          txtEmailNDACivilian.Text = rs!CivilianEmail
          txtPhoneNDACivilian.Text = rs!CivilianPhoneNumber
          cboClassApplied.Text = rs!ClassApplied
          cboSpecialDisability.Text = rs!SpecialDisability
          '
          rs.Update
          MsgBox "Record updated!", vbOKOnly + vbInformation, "Modify"
       End If
       rs.Close
       Set rs = Nothing
       '
       Con.Close
       Set Con = Nothing
    End Sub
    Last edited by zmbd; Jan 23 '13, 09:23 PM. Reason: [Ovees;{Did not enter operating system platform and version of Microsoft Access}] [Z:{Stepped code}]
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    line 8 in code block should be rs.edit
    This will still error if the connection is bad or there isn't a currently selected record.

    Line 7 doesn't make sense... you're editing the BOF (first record) or the EOF (last record)?

    The remaining code makes no sense in that it appears that you are changing the values of controls on the form, not copying values from the controls to the records.
    Last edited by zmbd; Jan 23 '13, 09:25 PM. Reason: [z{re-read the code just to get the blurry out my eyes}]

    Comment

    • Ovees
      New Member
      • Dec 2009
      • 2

      #3
      Thanks for your response. I still don't get it clear how can I modify the values in a control and then update it to a database please

      Comment

      • zmbd
        Recognized Expert Moderator Expert
        • Mar 2012
        • 5501

        #4
        Let's just look at line 8 in the OP code block:
        txtRegNo.Text = rs![RegNumber]

        In "english" what you are saying by this code is (in simple terms):
        With the control named "txtRegNo" let the property of that control named "Text" have the value of the field [RegNumber] in the recordset assigned to "rs"

        where what you need is:
        rs![RegNumber] = txtRegNo.Text
        let the field [RegNumber] in the recordset assigned to "RS" have the value taken from the property named "Text" from the control named "txtRegNo".

        Comment

        Working...