HandsOn Using the IfThenAND Conditional Statement

1. Insert a new module and enter the following IfThenAnd procedure in the module's Code window.

Sub IfThenAnd()

Dim price As Single Dim units As Integer Dim rebate As Single

Const strMsgl = "To get a rebate you must buy an additional " Const strMsg2 = "Price must equal $7.00"

If price = 7 And units >= 50 Then rebate = (price * units) * 0.1

Introduction to Access 2003 VBA Programming

MsgBox "The rebate is: $" & rebate End If

MsgBox strMsgl & "50 - units." End If

MsgBox strMsg2 End If

MsgBox "You didn't meet the criteria." End If End Sub

The IfThenAnd procedure shown above has four If.. .Then statements that are used to evaluate the contents of two variables: price and units. The AND operator between the keywords If.. .Then allows more than one condition to be tested. With the AND operator, all conditions must be true for Visual Basic to run the statements between the Then.. .End If keywords.

0 0

Post a comment