Results 1 to 6 of 6
  1. #1
    runner231 is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Jun 2018
    Posts
    6

    Cannot update. Database or object is read-only. (Error 3027)

    Dim db As DAO.Database
    Dim rec1 As DAO.Recordset
    Dim recFiltered1 As DAO.Recordset


    Set db = CurrentDb
    Set rec1 = db.OpenRecordset("SELECT [Product Suppliers Name].[Product ID], [Product Suppliers Name].[Supplier] FROM [Product Suppliers Name];", dbOpenDynaset, dbSeeChanges)
    rec1.Filter = "[Product ID] = " & Me.ID
    Set recFiltered1 = rec1.OpenRecordset
    If (Not (recFiltered1.EOF)) Then
    rec1.Edit
    rec1![Supplier] = supplierNameSavedinProductSupplierNametable
    rec1.Update
    Else


    rec1.AddNew
    rec1![Product ID] = Me.ID
    rec1![Supplier] = supplierNameSavedinProductSupplierNametable
    rec1.Update
    End If

    supplierNameSavedinProductSupplierNametable = ""
    Set rec1 = Nothing
    Set recFiltered1 = Nothing
    Set db = Nothing

    Hi Guys, can someone please advise what is wrong with my code. I encounter run time errror 3027. Thank you.

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,398
    it would be helpful to know what line of the code is highlighted when the error occurs

    Also, please use code tags to preserve the indentation of the code highlight the pasted code and click the # button - like this

    Code:
    Dim db As DAO.Database
     Dim rec1 As DAO.Recordset
     Dim recFiltered1 As DAO.Recordset
    
    
     Set db = CurrentDb
     Set rec1 = db.OpenRecordset("SELECT [Product Suppliers Name].[Product ID], [Product Suppliers Name].[Supplier] FROM [Product Suppliers Name];", dbOpenDynaset, dbSeeChanges)
     rec1.Filter = "[Product ID] = " & Me.ID
     Set recFiltered1 = rec1.OpenRecordset
     If (Not (recFiltered1.EOF)) Then
        rec1.Edit
        rec1![Supplier] = supplierNameSavedinProductSupplierNametable
        rec1.Update
     Else
        rec1.AddNew
        rec1![Product ID] = Me.ID
        rec1![Supplier] = supplierNameSavedinProductSupplierNametable
        rec1.Update
     End If
    
     supplierNameSavedinProductSupplierNametable = ""
     Set rec1 = Nothing
     Set recFiltered1 = Nothing
     Set db = Nothing
    Last edited by CJ_London; 08-15-2018 at 09:14 AM. Reason: error description in the title

  3. #3
    runner231 is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Jun 2018
    Posts
    6
    It is rec1.edit if the if condition is excuted. And it is rec1.addnew if the else condition is executed. Thanks

  4. #4
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    Wouldn't you want to use recFiltered1 instead of rec1 (like in recFiltered1.Edit and so on inside the if statement)?

    Cheers,
    Vlad

  5. #5
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,389
    Kinda confusing, and don't see need for 2 recordsets. Why not just construct the query with a WHERE clause to get the required Product_ID? Then use that query for the recordsource.
    Last edited by davegri; 08-15-2018 at 03:17 PM.

  6. #6
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101

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

Similar Threads

  1. Replies: 4
    Last Post: 09-08-2016, 12:11 PM
  2. Replies: 2
    Last Post: 12-19-2014, 07:41 AM
  3. Replies: 2
    Last Post: 11-18-2014, 08:56 AM
  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