'Object Required' error while addine new record using ADODC & MS Acces.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sneha Bele

    'Object Required' error while addine new record using ADODC & MS Acces.

    Hi, I am beginner in Visual Basic. I am doing a simple ADODC project using MS Acces. In that when I add new record to the database it gives me error 'Object Required'.
    I tried the same code onj different form but it is giving me same error. All the connections seem ok as the data is properly fetched at startup and ADODC control works fine navigating through db.
    Please help me. My code is as follows...

    Code:
    Private Sub Form_Load()
    Set adoRecordset = New Recordset
    
    Private Sub cmdAdd_Click()
    
    On Error GoTo ErrLabel
    adoRecordset.AddNew
    Exit Sub
    
    ErrLabel:
    MsgBox Err.Description
    End Sub
  • Stewart Ross
    Recognized Expert Moderator Specialist
    • Feb 2008
    • 2545

    #2
    Although you have defined your recordset variable and instantiated it using New you have not actually opened a recordset at all at the point where you've tried to add a new record - hence the error. You'll need to use the OpenRecordset method to open an updateable named table or query before you can add a new record. You'll also need to add code to define what field values you are going to update, as at present you don't have anything following the Addnew line at all.

    -Stewart

    Comment

    • Sneha Bele

      #3
      Thanks Stewart.
      I have tried your suggesion but its still not workin. also another problem is that although I have defined adoRecordset as New Recordset still when I use aadoRecordset VB doesn't prompt me method after '.'
      What can be the reason?

      I have tried the solution from 'Black Book' as below that too is not working. Please help.

      Code:
      Private Sub Form_Load()
      '----------------------------------------------------
      Dim db As Connection
      Set db = New Connection
      
      db.Open "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=C:\Documents and Settings\Nagendra\My Documents\Shanti Nursing Home\db.mdb"
      
      Set adoRecordset = New Recordset
      
      adoRecordset.Open "select Fname, Hname, Lname, Age, Gage, Mchild, Fchild from Patient", db, adOpenStatic, adLockOptimistic
      
      End Sub
      
      
      Private Sub cmdAdd_Click()
      
      On Error GoTo ErrLabel
      
      adoRecordset.AddNew
      
      txtFName.Text = ""
      txtHName.Text = ""
      txtLName.Text = ""
      txtAge.Text = ""
      
      Exit Sub
      
      ErrLabel:
      MsgBox Err.Description
      End Sub

      Comment

      Working...