Results 1 to 5 of 5
  1. #1
    templeowls is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    305

    Help to get rid of report name in print VBA

    Sorry for the confusing title. I've got a button on a report for the user to press and it prints out the report. See below:



    Code:
    Private Sub btnPrintReport_Click()On Error GoTo btnPrintReport_Click_Err
    
    
        DoCmd.OpenReport "rptComplaintNumber", acViewNormal, "", acNormal
    
    
    btnPrintReport_Click_Exit:
        Exit Sub
    
    
    btnPrintReport_Click_Err:
        MsgBox Error$
        Resume btnPrintReport_Click_Exit
    
    
    End Sub
    Is it possible to not have to cite the actual report name in the code? But rather have it refer to the currently open report maybe?

    I ask so that if I or others reuse this code for a different report, they don't need to remember to go into the VBA and change the report name.

    Thanks!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    Button on report only works in ReportView, not PrintPreview.

    But yes, can get report name, try: Me.Name
    Last edited by June7; 04-28-2022 at 06:16 PM.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,784
    This is re-inventing the wheel. Open in print preview and use the ribbon? I dunno, but reports seldom need or should have command buttons on them IMO.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    moke123's Avatar
    moke123 is online now Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,651
    I often have a print button on certain reports and prefer to use the print dialog.
    Set the "Display When" property of the button to screen only.

    Code:
    Private Sub btoPrint_Click()
    
    
        On Error GoTo btoPrint_Click_Error
        
    DoCmd.RunCommand acCmdPrint
        
        On Error GoTo 0
        Exit Sub
    
    
    btoPrint_Click_Error:
    
    
    If Err.Number = 2501 Then
    Exit Sub
    End If
    
    
        MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure btoPrint_Click, line " & Erl & "."
    
    
    End Sub
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  5. #5
    templeowls is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    305
    Quote Originally Posted by moke123 View Post
    I often have a print button on certain reports and prefer to use the print dialog.
    Set the "Display When" property of the button to screen only.

    Code:
    Private Sub btoPrint_Click()
    
    
        On Error GoTo btoPrint_Click_Error
        
    DoCmd.RunCommand acCmdPrint
        
        On Error GoTo 0
        Exit Sub
    
    
    btoPrint_Click_Error:
    
    
    If Err.Number = 2501 Then
    Exit Sub
    End If
    
    
        MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure btoPrint_Click, line " & Erl & "."
    
    
    End Sub
    That worked! Thanks so much!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 12-13-2018, 01:06 PM
  2. Replies: 3
    Last Post: 04-28-2017, 09:51 AM
  3. Replies: 5
    Last Post: 08-06-2015, 03:26 PM
  4. Replies: 1
    Last Post: 02-21-2015, 11:35 PM
  5. Replies: 6
    Last Post: 03-01-2014, 07:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums