Results 1 to 4 of 4
  1. #1
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496

    Edit the record you are on using dao

    Curious.

    If I am on a form's record and it is locked because I am using it - I can't edit that record using vba and dao.recordset?

    say

    rs.edit
    rs!field = 123
    rs.update

    If I do this I get a locked record.



    Should I remove focus or unlock the record somehow?

  2. #2
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Changing the value in a form control, either manually or using VBA, automatically changes the data in the underlying table record.

    Me![controlname] = 123 in VBA is the correct syntax, no need for a recordset reference.

    John

  3. #3
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by John_G View Post
    Changing the value in a form control, either manually or using VBA, automatically changes the data in the underlying table record.

    Me![controlname] = 123 in VBA is the correct syntax, no need for a recordset reference.

    John
    Sorry to confuse however it's not the syntax.

    I am on the record on the form. I click a button and it runs through the recordset with it filtering to the same record as the form. I go to edit that recordset and I get a lock error.

    dim db as dao.database
    dim rs as dao.recordset
    set db = currentdb
    set rs = db.openrecordset("SELECT * FROM qrySchools WHERE SchoolID =" & SchoolID)

    so since it is going to pick up the same as the one I am currently editing the form has locked that record.

    I get that I can use me. but I purposely want to use rs!

  4. #4
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    I get that I can use me. but I purposely want to use rs!
    Why do you need (or want) to use a recordset to update the current record? You've already seen that you can't, at least not the way you are trying to do it. You could try using a RecordSetClone to update the required record, followed by a Me.Requery to update the form recordset, but I've never done that, so I don't know it it will work.

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

Similar Threads

  1. navigate to a record and edit or replace it
    By graccess in forum Programming
    Replies: 11
    Last Post: 01-27-2014, 06:40 PM
  2. Replies: 32
    Last Post: 05-23-2013, 04:16 PM
  3. Use VBA to edit record or create new record in a query
    By ryantam626 in forum Programming
    Replies: 11
    Last Post: 08-09-2012, 02:37 AM
  4. Click a record to display it for edit
    By mapl in forum Access
    Replies: 0
    Last Post: 11-24-2008, 03:02 PM
  5. Can I edit a record with a subform?
    By bigmax in forum Forms
    Replies: 0
    Last Post: 08-11-2008, 07:55 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