none
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

    Else

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

                  CurrentDb.OpenRecordSet("BudgetAllocation").Edit

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

                  CurrentDb.OpenRecordSet("BudgetAllocation").Update

          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
            .Edit
                .Fields("AllocationAmount").value = maxAmount - spendAmount
            .Update
        End If
    End With

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

    Hope it helps...


    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

    Hi,

    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

    Hello,

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

    Thanks for your understanding.

    Regards,

    Celeste


    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
    Moderator