Results 1 to 6 of 6
  1. #1
    DC CS is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    Jan 2023
    Location
    Vaalpark, South Africa
    Posts
    68

    Error object is open read only

    Hi,
    Please see below code:



    Set Dbs4 = CurrentDb
    SQL4 = "SELECT StartDate, EndDate, CertNumber FROM Tbl_Certification_BrokenCourses " _
    & "GROUP BY StartDate, EndDate, CertNumber " _
    & "HAVING CertNumber = " & Val(Forms!Frm_CertificationEditDatesBrokenCourses. CertNumber) & " ORDER BY EndDate;"
    Set Rst4 = Dbs4.OpenRecordset(SQL4)


    Rst4.MoveLast: Rst4.MoveFirst
    i = 1
    With Rst4
    .Edit
    !StartDate = Me("StartDate" & i)
    !EndDate = Me("EndDate" & i)
    .Update
    i = i + 1
    Rst4.MoveNext
    End With

    Once the ".Edit" is executed, I get the error 3027 - Object is read only.

    Does someone know why? I have other code with the ".Edit" and runs without any issues.

    Thanks

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,927
    Try editing that as a query.?
    If you cannot, then it is read only.

    You can also pass a parameter to OpenRecordset https://learn.microsoft.com/en-us/of...set-method-dao
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    DC CS is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    Jan 2023
    Location
    Vaalpark, South Africa
    Posts
    68
    I found the culprit - it is due to the GROUP BY clause.

    How do one substitute the GROUP BY clause?

  4. #4
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    With great difficulty if you want to group the records. Once grouped you have a set of non uniquely-identifiable records.

    You could simply use an update query (rather than looping through them) joined to the courses you select via your grouping query, but it will by definition update all of the records returned.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,927
    Perhaps DISTINCT ?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    DC CS is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    Jan 2023
    Location
    Vaalpark, South Africa
    Posts
    68
    Hi all,
    Thanks for the assistance. The UPDATE query is doing the job.
    A bit more coding, but it works

    DISTINCT only retrieves 1 of the duplicate records, and not all 7 of them.

    Thanks

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

Similar Threads

  1. Replies: 5
    Last Post: 08-15-2018, 02:52 PM
  2. Replies: 3
    Last Post: 07-20-2015, 12:23 PM
  3. Replies: 5
    Last Post: 04-22-2013, 12:32 PM
  4. Cannot update. Database or object is read-only ERROR
    By Namibia in forum Import/Export Data
    Replies: 2
    Last Post: 06-05-2012, 05:32 PM
  5. Runtime Error '3027': Database or object is read only
    By 4x4Masters in forum Programming
    Replies: 4
    Last Post: 06-08-2010, 08:02 PM

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