Unable to change field value of Object in before Update event in access

32 Views Asked by At

I have a form in MS access 2013 to manage transferring material (Add, Return) between the company project sites, When return item to any project, i have code to validate the value entered in the txtReturn_Qty field before the record is updated. If the value entered is greater than the available balance, a message box is displayed and the update is cancelled. using query "Project_Process_Balance"

My problem is after updating the record, I'm unable to change field value (txtReturn_Qty) i have to delete the record and re-enter the new value.

Private Sub Form_BeforeUpdate(Cancel As Integer)

Const MESSAGE_TEXT1 = "The item not Transferred from the selected project."
Const MESSAGE_TEXT2 = "Insufficient item stock from the selected project."

Dim strX As Integer

If Me.Parent!Process_Type = "Return" Then

        If IsNull(DLookup("[Balance]", "Project_Process_Balance", "[ItemNo] = " & Me.txtItemNo & " And [ProjectID] = " & Me.Parent!cboProjectName & " And [Status_ID] = " & Me.txtStatus)) Then
        MsgBox MESSAGE_TEXT1, vbExclamation, "Invalid Operation"
        Cancel = True

        Else
        strX = DLookup("[Balance]", "Project_Process_Balance", "[ItemNo] = " & Me.txtItemNo & " And [ProjectID] = " & Me.Parent!cboProjectName & " And [Status_ID] = " & Me.txtStatus)

            If Me.txtReturn_Qty > strX Then
            MsgBox MESSAGE_TEXT2, vbExclamation, "Invalid Operation"
            Cancel = True
            End If
        End If
End If

End Sub

thanks in advance

0

There are 0 best solutions below