
'----------------------------------------------------------------
' Hands-On 25-1  - Code for the rptCustomers report
'----------------------------------------------------------------

Private Sub Report_Open(Cancel As Integer)
    Dim strCustName As String
    Dim strSQL As String
    Dim strWHERE As String

    On Error GoTo ErrHandler
    strSQL = "SELECT * from Customers"

    strCustName = InputBox("Type the first letter of " & _
        " the Company Name or type an asterisk (*) to view" & _
        " all companies.", "Show All /Or Filter")

    If strCustName = "" Then
        Cancel = True
    ElseIf strCustName = "*" Then
        Me.RecordSource = strSQL
        Me.lblCustomers.Caption = "All Customers"
    Else
      strCustName = "'" & Trim(strCustName) & "*" & "'"
      strWHERE = " WHERE CompanyName Like " _
           & strCustName & ""
      Debug.Print strSQL
      Debug.Print strWHERE
      Me.RecordSource = strSQL & strWHERE
      Me.lblCustomers.Caption = "Selected Customers" & _
          " (" & UCase(strCustName) & ")"
    End If
    Exit Sub
ErrHandler:
        MsgBox Err.Description
End Sub


'----------------------------------------------------------------
' Hands-On 25-2 - Code for the rptCustomers report
'----------------------------------------------------------------

Private Sub Report_Activate()
    If Me.CurrentView = acCurViewPreview Then
    MsgBox "Activating Print Preview of " _
        & Me.Name & " report."
        Debug.Print "Default Printer: " & _
        Application.Printer.DeviceName
    End If
End Sub


'----------------------------------------------------------------
' Hands-On 25-3 - Code for the rptCustomers report
'----------------------------------------------------------------

Private Sub Report_NoData(Cancel As Integer)
    MsgBox "There is no data for the criteria " & _
        "you entered."
    Cancel = True
End Sub


'----------------------------------------------------------------
' Hands-On 25-4 - Code for the rptCustomers report
'----------------------------------------------------------------

Private Sub Report_Page()
    Me.DrawWidth = 15 ' pixels
    Me.Line (0, 0)-(Me.ScaleWidth, _
        Me.ScaleHeight), vbRed, B
End Sub


'----------------------------------------------------------------
' Hands-On 25-5 - Code for the rptCustomers report
'----------------------------------------------------------------

Private Sub Report_Error(DataErr As Integer, _
            Response As Integer)
    ' obtain information about the error
   ' MsgBox Application.AccessError(DataErr), _
        vbOKOnly, "Error Number: " & DataErr
    If DataErr = 3078 Then
    Response = acDataErrContinue
        MsgBox "Your custom error message goes here."
    End If
End Sub


'----------------------------------------------------------------
' Hands-On 25-6 - Code for the rptCustomers report
'----------------------------------------------------------------


' Enter the following declaration at the top of the module
Dim shaded As Boolean


Private Sub Detail_Format(Cancel As Integer, _
            FormatCount As Integer)
    
    If shaded Then
        Me.Detail.BackColor = vbYellow
    Else
        Me.Detail.BackColor = vbWhite
    End If
    shaded = Not shaded
End Sub


'----------------------------------------------------------------
' Hands-On 25-7 - Code for the rptProducts report
'----------------------------------------------------------------

Private Sub PageFooterSection_Format(Cancel As Integer, _
    FormatCount As Integer)
    
    Dim ctrl As Control

    For Each ctrl In Me.PageFooterSection.Controls
        If Me.Page = 1 Then
            ctrl.Visible = False
        Else
            ctrl.Visible = True
        End If
    Next ctrl
End Sub


'----------------------------------------------------------------
' Hands-On 25-8 - Code for the rptCustomers report
'----------------------------------------------------------------

Private Sub Detail_Print(Cancel As Integer, _
            PrintCount As Integer)
    Static rCount As Integer
    Static start As Integer
    Static firstId As String
    Static lastId As String

    If Me.Page <> Me.txtPage Then
        start = Me.CurrentRecord
        firstId = CustomerID
        Me.txtPage = Me.Page
        rCount = 0
    End If
        rCount = rCount + 1
        lastId = CustomerID
    If start <= rCount Then
        Me.txtRange = start & "-" & rCount
      ' Me.txtRange = UCase(firstId) & "-" & UCase(lastId)
    Else
        rCount = Me.CurrentRecord
        lastId = CustomerID
    End If
End Sub


Private Sub PageHeaderSection_Print(Cancel As Integer, _
                              PrintCount As Integer)
    Me.txtPage = 0
End Sub


