Reputation: 215
I am using AfterUpdate event to update a Textbox whose condition depends on multiple conditions. The first part of my code works fine but the second part does not do anything. I assume its because VBA Exits Sub soon as the first parts condition is met. Is there a way to work around it? I am still new to VBA and I am struggling with this. Any suggestions is highly appreciated
Private Sub QuantityUsed_AfterUpdate()
If IsNull(QuantityUsed) Then
QuantityUsed = 0
Else: QuantityUsed = QuantityUsed.Value
End If
'First part__________________
If Used1.Value > Total1.Value Then
Exit Sub
End If
If Used1.Value = 0 Then
Exit Sub
End If
QuantityUsed = QuantityUsed.Value + Used1
'Second part__________________
If Used2.Value > Total2.Value Then
Exit Sub
End If
If Used2.Value = 0 Then
Exit Sub
End If
QuantityUsed = QuantityUsed.Value + Used2
End Sub
Upvotes: 0
Views: 337
Reputation: 8518
How about changing the IF
statement a bit?
'...
If Not Used1.Value > Total1.Value And Used1.Value <> 0 Then
QuantityUsed = QuantityUsed.Value + Used1
End If
'...
Upvotes: 3