Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Mar 2006
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    289
    Thanks
    0
    Thanked 1 Time in 1 Post

    Syntax (2003 sp2)

    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").OpenRe cordset
    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
    Thanks
    chuck

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Syntax (2003 sp2)

    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").OpenRe cordset
    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.

  3. #3
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Syntax (2003 sp2)

    The sequence should be this:

    rst.MoveLast
    RCount = rst.RecordCount
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  4. #4
    3 Star Lounger
    Join Date
    Mar 2006
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    289
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Syntax (2003 sp2)

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

    And Hans, thanks for the explanation.
    Thanks
    chuck

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •