Run-time error 3020; Update or CancelUpdate without AddNew or Edit

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AndyB2
    New Member
    • Dec 2011
    • 49

    #1

    Run-time error 3020; Update or CancelUpdate without AddNew or Edit

    Using Access 2010
    Windows 7

    I'm sure this is a simple VBA Gramer problem.

    I am attempting to update a table.

    Below is the code and I'm getting the error on the line BOM("Level") = 1, Line 21. I'm sure lines 22, 25, and 27 will have the same issue.


    Code:
    Private Sub CB_RunQueryPrintReport_Click()
    
    Dim stDocName As String
    Dim Filename As String
    Dim i, RC, X As Integer
    Dim MyDB As DAO.Database
    Dim REQ, BOM As DAO.Recordset
    Dim UDI As DAO.Recordset2
    'Dim BOM As DAO.Recordset
    Dim CurrSpecies As String
    
    Set MyDB = DBEngine.Workspaces(0).Databases(0)
    Set REQ = MyDB.OpenRecordset("Tbl_REQData", DB_OPEN_TABLE)
    Set UDI = MyDB.OpenRecordset("Tbl_UDIData", DB_OPEN_TABLE)
    Set BOM = MyDB.OpenRecordset("Tbl_BOM_Level", DB_OPEN_TABLE)
    
    DoCmd.Hourglass True
    DoCmd.SetWarnings False
    
    i = 0
    BOM("Level") = i
    BOM("Prev Level") = i
    DoCmd.OpenQuery "Qry_FindPanelParts"
    For i = 1 To 7
        BOM("Level") = i
        DoCmd.OpenQuery "Qry_FindPanelPartsNextLevelDown"
        BOM("Prev Level") = i
    Next i
    
    etc... error is above:
  • Seth Schrock
    Recognized Expert Specialist
    • Dec 2010
    • 2965

    #2
    In order to edit a recordsource in VBA, you must use the Edit method (as the error states). So what you need is something like:
    Code:
    With BOM
         .Edit
         !Level = i
         !Prev Level = i
         .Update
    End With
    This replaces lines 21, 22, 25, & 27.

    Here is a link that explains the Edit method: Recordset.Edit Method
    Last edited by Seth Schrock; Jan 7 '13, 04:52 PM. Reason: Added Link

    Comment

    Working...