VBA code, need help

Function DefineOrderChanges()
    Dim rsOO As DAO.Recordset ' open orders
    Dim rsCH As DAO.Recordset ' order change history
    Dim rcOO As Long ' record count in the open order recordset
    
    Set rsOO = CurrentDb.OpenRecordset("OpenOrdersOnOrderImportFile")
    Set rsCH = CurrentDb.OpenRecordset("OrderChanges")
    If rsOO.RecordCount = 0 Then
        Set rsOO = Nothing
        Set rsCH = Nothing
        Exit Function
    End If
    
    With rsOO
        .MoveLast
        rcOO = .RecordCount
        .MoveFirst
        
        For i = 1 To rcOO
            
            If .Fields("OrdersRawData.Detailer/Engineer") <> .Fields("Orders.Detailer/Engineer") Then
                ' write a record to the change table
                rsCH.AddNew
                rsCH.Fields("Project") = .Fields("Project")
                rsCH.Fields("CustomizedItem") = .Fields("CustomizedItem")
                rsCH.Fields("DateAdded") = Now()
                rsCH.Fields("Field") = "Detailer/Engineer"
                rsCH.Fields("OldValue") = .Fields("Orders.Detailer/Engineer")
                rsCH.Fields("NewValue") = .Fields("OrdersRawData.Detailer/Engineer")
                rsCH.Fields("RequestedBy") = "BAAN"
                If IsNull(.Fields("DateAssigned")) Then rsCH.Fields("ChangeAck") = -1
                rsCH.Update
                ' now make the change to the existing order
                .Edit
                .Fields("Orders.Detailer/Engineer") = .Fields("OrdersRawData.Detailer/Engineer")
                .Update
                
            End If
            If .Fields("Name") <> .Fields("CustName") Then
                ' write a record to the change table
                rsCH.AddNew
                rsCH.Fields("Project") = .Fields("Project")
                rsCH.Fields("CustomizedItem") = .Fields("CustomizedItem")
                rsCH.Fields("DateAdded") = Now()
                rsCH.Fields("Field") = "CustName"
                rsCH.Fields("OldValue") = .Fields("CustName")
                rsCH.Fields("NewValue") = .Fields("Name")
                rsCH.Fields("RequestedBy") = "BAAN"
                If IsNull(.Fields("DateAssigned")) Then rsCH.Fields("ChangeAck") = -1
                rsCH.Update
                ' now make the change to the existing order
                .Edit
                .Fields("CustName") = .Fields("Name")
                .Update
            End If
            If .Fields("OrdersRawData.Description") <> .Fields("Orders.Description") Then
                ' write a record to the change table
                rsCH.AddNew
                rsCH.Fields("Project") = .Fields("Project")
                rsCH.Fields("CustomizedItem") = .Fields("CustomizedItem")
                rsCH.Fields("DateAdded") = Now()
                rsCH.Fields("Field") = "Description"
                rsCH.Fields("OldValue") = .Fields("Orders.Description")
                rsCH.Fields("NewValue") = .Fields("OrdersRawData.Description")
                rsCH.Fields("RequestedBy") = "BAAN"
                If IsNull(.Fields("DateAssigned")) Then rsCH.Fields("ChangeAck") = -1
                rsCH.Update
                ' now make the change to the existing order
                .Edit
                .Fields("Orders.Description") = .Fields("OrdersRawData.Description")
                .Update
            End If
            If .Fields("Order Qty") <> .Fields("OrderQty") Then
                ' write a record to the change table
                rsCH.AddNew
                rsCH.Fields("Project") = .Fields("Project")
                rsCH.Fields("CustomizedItem") = .Fields("CustomizedItem")
                rsCH.Fields("DateAdded") = Now()
                rsCH.Fields("Field") = "OrderQty"
                rsCH.Fields("OldValue") = .Fields("OrderQty")
                rsCH.Fields("NewValue") = .Fields("Order Qty")
                rsCH.Fields("RequestedBy") = "BAAN"
                If IsNull(.Fields("DateAssigned")) Then rsCH.Fields("ChangeAck") = -1
                rsCH.Update
                ' now make the change to the existing order
                .Edit
                .Fields("OrderQty") = .Fields("Order Qty")
                .Update
            End If
            If .Fields("Planned Start Date") <> .Fields("PlannedStartDate") Then
                ' write a record to the change table
                rsCH.AddNew
                rsCH.Fields("Project") = .Fields("Project")
                rsCH.Fields("CustomizedItem") = .Fields("CustomizedItem")
                rsCH.Fields("DateAdded") = Now()
                rsCH.Fields("Field") = "PlannedStartDate"
                rsCH.Fields("OldValue") = .Fields("PlannedStartDate")
                rsCH.Fields("NewValue") = .Fields("Planned Start Date")
                rsCH.Fields("RequestedBy") = "BAAN"
                If IsNull(.Fields("DateAssigned")) Then rsCH.Fields("ChangeAck") = -1
                rsCH.Update
                ' now make the change to the existing order
                .Edit
                .Fields("PlannedStartDate") = .Fields("Planned Start Date")
                .Update
            End If
            If .Fields("Req'd Release from Engr") <> .Fields("ReqReleaseFromEngr") Then
                ' write a record to the change table
                rsCH.AddNew
                rsCH.Fields("Project") = .Fields("Project")
                rsCH.Fields("CustomizedItem") = .Fields("CustomizedItem")
                rsCH.Fields("DateAdded") = Now()
                rsCH.Fields("Field") = "ReqReleaseFromEngr"
                rsCH.Fields("OldValue") = .Fields("ReqReleaseFromEngr")
                rsCH.Fields("NewValue") = .Fields("Req'd Release from Engr")
                rsCH.Fields("RequestedBy") = "BAAN"
                If IsNull(.Fields("DateAssigned")) Then rsCH.Fields("ChangeAck") = -1
                rsCH.Update
                ' now make the change to the existing order
                .Edit
                .Fields("ReqReleaseFromEngr") = .Fields("Req'd Release from Engr")
                .Update
            End If
            .MoveNext
        Next
    End With
    
    Set rsOO = Nothing
    Set rsCH = Nothing
    
            
         
End Function

Hi @alopez802, and welcome to the community.

It’s not clear what you’re asking for exactly, Please provide some context to the code you’ve posted.

Sorry about that. Everytime I run this code, I get a run-time error ‘3027’. Cannot update. Database or object is read-only. The database nor the object is read-only, I dont understand. This is a part of a submacro that runs this code. There are other submacros that are run before it runs this code. The error happens at the ".Edit " right before the " If .Fields(“Req’d Release from Engr”) <> .Fields(“ReqReleaseFromEngr”) Then ". The error is the same with a smaller amount of code. Say I remove the If statement where the error is at, it will just indicate there is an error at the .Edit of some other If statement.

From what I know the database isnt in read-only, unless im looking at the wrong place. Do you know where i can see if the database isnt in read-only mode?

Hard to tell, the context is still generic — the macro is interacting with which program? Access? Excel?

Maybe it’s related to this:

https://bytes.com/topic/access/answers/919418-ms-access-err-run-time-error-3027-cannot-update-database-object-read-only