Results 1 to 4 of 4
  1. #1
    Philosophaie is offline Novice
    Windows Vista Access 2010 32bit
    Join Date
    Aug 2012
    Posts
    28

    Edit a preexisting database using RecordSets


    Set up a database and recordset that works in Excel 2007.
    Error in rs.Edit.
    Does .Edit need a separate Tools>References that I do not already have?
    Or how do you edit a preexisting database using RecordSets?


    Code:
        rs.MoveFirst
        Do Until rs.EOF
           If rs!Index = "106" Then
              rs.Edit
              rs!AmtPaid = "500"
              rs.Update
           End If
           rs.MoveNext
        Loop

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    If it gets to that point, I'd guess the recordset was opened on a read only source, or was opened in read only mode. By the way, an update query would be far more efficient than a loop.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    DepricatedZero's Avatar
    DepricatedZero is offline Cthulhu Fhtagn!
    Windows 8 Access 2007
    Join Date
    Apr 2013
    Location
    Cincinnati
    Posts
    65
    the RecordSet should be declared from a Database object. Set the database to the preexisting DB, like so

    Code:
    Private Sub EditExternalDB()
       Dim db as DAO.Database
       Dim rs as DAO.Recordset
    
       Set db = OpenDatabase("C:\Path\Example.accdb")
       Set rs = db.OpenRecordset("QueryName")
    
       
       rs.MoveFirst
       Do Until rs.EOF
          If rs!Index = "106" Then
              rs.Edit
              rs!AmtPaid = "500"
              rs.Update
           End If
           rs.MoveNext
       Loop
       rs.close
       db.closeEnd Sub
    What's the error that you're getting?

  4. #4
    Philosophaie is offline Novice
    Windows Vista Access 2010 32bit
    Join Date
    Aug 2012
    Posts
    28
    Neglected in putting in my db and rs but they work.
    Getting an error in rs.Edit it would not debug in Excel 2007 or Excel 2010.
    Found it in the MSDN website but it did not say if it needed any extra references other than DAO and ActiveX.
    Last edited by Philosophaie; 05-06-2013 at 02:03 PM.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 15
    Last Post: 03-21-2012, 08:44 PM
  2. Replies: 2
    Last Post: 01-11-2012, 12:19 PM
  3. Edit reports while others are in the database
    By nkuebelbeck in forum Access
    Replies: 6
    Last Post: 09-15-2011, 03:07 PM
  4. Replies: 12
    Last Post: 06-16-2011, 01:35 PM
  5. Database Won't Open To Edit??
    By dapoole in forum Access
    Replies: 2
    Last Post: 10-04-2010, 07:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums