Results 1 to 6 of 6
  1. #1
    Star Lounger
    Join Date
    Feb 2003
    Location
    DC Metro, District Of Columbia, USA
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts

    acCmdPrint (2003,set to 2k compat.)

    Hi all:
    For a report, I want the user to select any network printer, thus DoCmd.RunCommand acCmdPrint. I do not know how to 'successfully' run the report and tell acCmdPrint to print 'that' report. BTW, DoCmd.SetWarnings False (if user cancels print) won't suppress the system/Access messagebox. I believe this is where I mutter Help! <grin>. Some code I have tried follows:
    ***************************************
    Private Sub cmdLookMarWOReport_Click()
    On Error GoTo Err_cmdLookMarWOReport_Click

    Dim stDocName As String

    stDocName = "rptMarWOSummary"
    'DoCmd.OpenReport stDocName, acPreview, , , acWindowNormal
    'DoCmd.OpenReport stDocName, acViewPreview
    'DoCmd.OpenReport reportname:="rptMarWOSummary", view:=acViewPreview
    'DoCmd.OpenReport reportname:="rptMarWOSummary", view:=acPreview
    DoCmd.OpenReport stDocName, acViewPreview

    Exit_cmdLookMarWOReport_Click:
    Exit Sub

    Err_cmdLookMarWOReport_Click:
    MsgBox Err.Description
    Resume Exit_cmdLookMarWOReport_Click

    End Sub

    Private Sub cmdPrintMarWOReport_Click()
    On Error GoTo Err_cmdPrintMarWOReport_Click

    Dim stDocName As String

    stDocName = "rptMarWOSummary"
    DoCmd.SetWarnings False
    DoCmd.OpenReport stDocName, acViewPreview, , , acHidden
    DoCmd.RunCommand acCmdPrint
    DoCmd.SetWarnings True

    Exit_cmdPrintMarWOReport_Click:

    Exit Sub

    Err_cmdPrintMarWOReport_Click:
    MsgBox Err.Description
    Resume Exit_cmdPrintMarWOReport_Click

    End Sub
    *********************************************
    TIA, JL

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

    Re: acCmdPrint (2003,set to 2k compat.)

    RunCommand acCmdPrint (you don't need DoCmd in front of it) will print whatever is open, or if the database window is active, whatever is selected there. So you can use

    DoCmd.SelectObject acReport, stDocName , True
    RunCommand acCmdPrint

    If the user cancels the print, error 2501 occurs. You can ignore this error:

    Err_cmdPrintMarWOReport_Click:
    If Err = 2501 Then
    ' Ignore cancel
    Else
    MsgBox Err.Description
    End If
    Resume Exit_cmdPrintMarWOReport_Click
    End Sub

  3. #3
    Star Lounger
    Join Date
    Feb 2003
    Location
    DC Metro, District Of Columbia, USA
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: acCmdPrint (2003,set to 2k compat.)

    Thank you Hans, I will try this. I really do appreciate all of the MVP's who monitor the forum, and Woody, and ***, of course, for hosting the forum. All of you combine to make our lives better, if more work, cuz we are seen as people who get the job done <big grin>. 10Q, JL.

  4. #4
    Star Lounger
    Join Date
    Feb 2003
    Location
    DC Metro, District Of Columbia, USA
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: acCmdPrint (2003,set to 2k compat.)

    Hans:
    It works (here is the over-used but <g>), but,,,, I call this print from a form command button and I would like to return from the print to the form. Please?? JL

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

    Re: acCmdPrint (2003,set to 2k compat.)

    Add an instruction

    Me.SetFocus

    or

    DoCmd.SelectObject acForm, Me.Name, False

    immediately below Exit_cmdPrintMarWOReport_Click:, before Exit Sub.

  6. #6
    Star Lounger
    Join Date
    Feb 2003
    Location
    DC Metro, District Of Columbia, USA
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: acCmdPrint (2003,set to 2k compat.)

    Hans:
    Works for me. Again, tanx lots. Back to work<g>.

Posting Permissions

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