In the following example, the BeforeUserChanged event procedure runs for the Invoice Entry window’s Trade Discount field. Using the CancelLogic parameter, it cancels processing for the Trade Discount field if the user enters an amount greater than 4% of the invoice subtotal. It also uses the KeepFocus parameter to place the focus in the same field, allowing the user to enter a lower amount:
Private Sub TradeDiscount_BeforeUserChanged(KeepFocus As Boolean, _ CancelLogic As Boolean) If TradeDiscount > Subtotal * 0.04 Then 'The trade discount is greater than 4% of the subtotal MsgBox "You cannot enter a discount greater than 4% of " + _ "the subtotal." 'Cancel the invoice calculation CancelLogic = True TradeDiscount.Empty = True KeepFocus = True End If End Sub