Run-Time Error 3020 RRS feed

  • Question

  • I'm new to access and I'm having trouble with the following code:

    Private sub MoneyAmount_AfterUpdate()

    Dim allocID As String

    allocID = AllocationID.Value

    Dim spendAmount as Double

    spendAmount = MoneyAmount.Value

    Dim maxAmount As Double

    maxAmount = DLookup("[AllocationAmount]", "BudgetAllocation", "[AllocationID] = '"&allocID&"'")

    Dim response As Integer

    If spendAmount > maxAmount Then

           response = MsgBox("Insufficient funds in this allocation", vbOKOnly + vbExclamation, "ERROR")

           MoneyAmount.Value = Null


           If CurrentDb.OpenRecordSet("BudgetAllocation").Fields("AllocationID").Value = allocID Then


                  CurrentDb.OpenRecordSet("BudgetAllocation").Fields("AllocationAmount").value = maxAmount - spendAmount


          End If

    End If

    End Sub

    It keeps giving me Run-Time error 3020, whenever I try to update to the record (i.e when spendAmount > maxAmount).  I was googling the problem, and it seems that the .edit and .update statements should allow me to update the record.  Any thoughts on where I'm going wrong?

    Friday, May 12, 2017 4:04 PM

All replies

  • Hi,

    Pardon me but what is runtime error 3020? Thanks.

    Friday, May 12, 2017 4:13 PM
  • With CurrentDb.OpenRecordSet("BudgetAllocation")
        If .Fields("AllocationID").Value = allocID Then
                .Fields("AllocationAmount").value = maxAmount - spendAmount
        End If
    End With

    Or, you could try modifying your code using the above structure.

    Hope it helps...

    • Edited by .theDBguy Friday, May 12, 2017 4:18 PM
    • Proposed as answer by Chenchen Li Monday, May 15, 2017 2:14 AM
    Friday, May 12, 2017 4:17 PM
  • That works!!!  Thank you so much for your help

    Friday, May 12, 2017 4:23 PM
  • That works!!!  Thank you so much for your help


    You're welcome! Glad we could help. Good luck with your project.

    Friday, May 12, 2017 4:24 PM
  • That works!!!  Thank you so much for your help


    I suggest you mark helpful post as answer to close this thread.

    Thanks for your understanding.



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, May 15, 2017 2:15 AM