' ----------------------------------------------------------------
' Hands-On 5-1
' ----------------------------------------------------------------

Sub SimpleIfThen()
    Dim weeks As String

    weeks = InputBox("How many weeks are in a year:", "Quiz")
    If weeks<>52 Then MsgBox "Try Again"
End Sub

Sub SimpleIfThen2()
    Dim weeks As String

    On Error GoTo VeryEnd
    weeks = InputBox("How many weeks are in a year:", "Quiz")
    If weeks <> 52 Then MsgBox "Try Again":SimpleIfThen2
    If weeks = 52 Then MsgBox "Congratulations!"
VeryEnd:
End Sub

' ----------------------------------------------------------------
' Hands-On 5-2
' ----------------------------------------------------------------

Sub SimpleIfThen3()
    Dim weeks As String
    Dim response As String
    
    On Error GoTo VeryEnd
    weeks = InputBox("How many weeks are in a year?", "Quiz")
    If weeks <> 52 Then
        response = MsgBox("This is incorrect. Would you like to try again?", _
        vbYesNo + vbInformation + vbDefaultButton1, _
        "Continue Quiz?")
        If response = vbYes Then
            Call SimpleIfThen3
        End If
    End If
VeryEnd:
End Sub

' ----------------------------------------------------------------
' Hands-On 5-3
' ----------------------------------------------------------------

Sub IfThenAnd()
    Dim price As Single
    Dim units As Integer
    Dim rebate As Single
    
    Const strMsg1 = "To get a rebate you must buy an additional "
    Const strMsg2 = "Price must equal $7.00"
    
    units = 234
    price = 7
    
    If price = 7 And units >= 50 Then
        rebate = (price * units) * 0.1
        MsgBox "The rebate is: $" & rebate
    End If
    
    If price = 7 And units < 50 Then
        MsgBox strMsg1 & " 50 - units."
    End If
    
    If price <> 7 And units >= 50 Then
        MsgBox strMsg2
    End If
    
    If price <> 7 And units < 50 Then
        MsgBox "You didn't meet the criteria."
    End If
End Sub

' ----------------------------------------------------------------
' Hands-On 5-4
' ----------------------------------------------------------------

Sub WhatTypeOfDay()
    Dim response As String
    Dim question As String
    Dim strMsg1 As String, strMsg2 As String
    Dim myDate As Date
    
    question = "Enter any date in the format mm/dd/yyyy:" _
            & Chr(13) & " (e.g., 11/22/2007)"
    strMsg1 = "weekday"
    strMsg2 = "weekend"
    response = InputBox(question)
    myDate = Weekday(CDate(response))
    
    If myDate >= 2 And myDate <= 6 Then
        MsgBox strMsg1
    Else
        MsgBox strMsg2
    End If
End Sub

' ----------------------------------------------------------------
' Hands-On 5-5
' ----------------------------------------------------------------

Private Sub cmdOK_Click()
    If txtPwd = "FOX" Then
            MsgBox "You are not authorized to run this report."
    ElseIf txtPwd = "DOG" Then
            If txtUser = "John" Then
                MsgBox "You are logged on with restricted privileges."
            ElseIf txtUser = "Mark" Then
                MsgBox "Contact the Admin now."
            ElseIf txtUser = "Anne" Then
                MsgBox "Go home."
            Else
                MsgBox "Incorrect User name."
            End If
    Else
        MsgBox "Incorrect password or user name"
    End If
    Me.txtUser.SetFocus
End Sub

' ----------------------------------------------------------------
' Hands-On 5-6
' ----------------------------------------------------------------

Sub TestButtons()
    Dim question As String
    Dim bts As Integer
    Dim myTitle As String
    Dim myButton As Integer
    
    question = "Do you want to preview the report now?"
    bts = vbYesNoCancel + vbQuestion + vbDefaultButton1
    myTitle = "Report"
    myButton = MsgBox(prompt:=question, buttons:=bts, Title:=myTitle)
    
    Select Case myButton
        Case 6
            DoCmd.OpenReport "Sales by Year", acPreview
        Case 7
            MsgBox "You can review the report later."
        Case Else
           MsgBox "You pressed Cancel."
    End Select
End Sub

' ----------------------------------------------------------------
' Hands-On 5-7
' ----------------------------------------------------------------

Sub DisplayDiscount()
    Dim unitsSold As Integer
    Dim myDiscount As Single
    
    unitsSold = InputBox("Enter the number of sold units:")
    myDiscount = GetDiscount(unitsSold)
    MsgBox myDiscount
End Sub

Function GetDiscount(unitsSold As Integer)
    Select Case unitsSold
        Case 1 To 200
            GetDiscount = 0.05
        Case 201 To 500
            GetDiscount = 0.1
        Case 501 To 1000
            GetDiscount = 0.15
        Case Is > 1000
            GetDiscount = 0.2
    End Select
End Function
