• Syntax (2003 sp2)

    Author
    Topic
    #443860

    I have a report that prints over 200 pages. I want to warn the user in a simple message before the report prints. In the following procedure the message states 0 pages even though when I step through the code the variable holds 266. What have I done wrong?

    Private Sub PrintForms_Click()
    Dim rst As DAO.Recordset, RCount As Integer
    Dim strMessage As String
    Dim bytChoice As Byte
    On Error GoTo PrintForms_Click_Error
    strMessage = “You are about to print ” & RCount & ” pages.”
    Set rst = CurrentDb.TableDefs(“tbl_ANNUAL_REVIEWS_1”).OpenRecordset
    RCount = rst.RecordCount
    rst.MoveLast
    bytChoice = MsgBox(strMessage, vbInformation + vbOKCancel, conAppName2)
    If bytChoice = vbOK Then
    OpenReports (“rpt_REPORTS_ALL”)
    ElseIf bytChoice = vbCancel Then
    DoCmd.CancelEvent
    End If
    rst.Close
    Set rst = Nothing
    On Error GoTo 0
    Exit Sub
    PrintForms_Click_Error:
    MsgBox “Error ” & Err.Number & ” (” & Err.Description & “) in procedure PrintForms”
    End Sub

    Viewing 1 reply thread
    Author
    Replies
    • #1071743

      The order of the instructions is wrong. You assign a value to strMessage when RCount is still 0, then assign a value to RCount and still later move to the last record of the recordset. The order should be

      Set rst = CurrentDb.TableDefs(“tbl_ANNUAL_REVIEWS_1”).OpenRecordset
      rst.MoveLast
      RCount = rst.RecordCount
      strMessage = “You are about to print ” & RCount & ” pages.”

      This way, you assign a value to strMessage after assigning a value to RCount.

    • #1071745

      The sequence should be this:

      rst.MoveLast
      RCount = rst.RecordCount

      • #1071781

        I was all around it and no where near it. I knew it had to be something simple.

        And Hans, thanks for the explanation.

    Viewing 1 reply thread
    Reply To: Syntax (2003 sp2)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: