Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
The Select Case structure is another tool for VBA programmers to use to build conditions. Specifically, the Select Case structure evaluates an expression only once. It’s useful for comparing a single expression to multiple values.
Select Case sDay
Case “Monday”
Me.lblDay.Caption = “Weekday”
Case “Tuesday”
Me.lblDay.Caption = “Weekday”
Case “Wednesday”
Me.lblDay.Caption = “Weekday”
Case “Thursday”
Me.lblDay.Caption = “Weekday”
Case “Friday”
Me.lblDay.Caption = “Weekday”
Case Else
Me.lblDay.Caption = “Weekend!”
End Select
In this case (excuse the pun) the Select Case structure evaluates a string-based variable and uses five Case statements to define possible expression values. The Case Else statement catches a value in the top expression that is not defined in a Case statement.