I need a VBA code to print the report

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • accessbeginner
    New Member
    • Apr 2014
    • 4

    #1

    I need a VBA code to print the report

    Hi,
    I have a report named PIRREPORTFORMD1 7792. Every time I try to print out a record, the MS Access 2010 uses PIRREPORTFORMD1 7792 as a default file name.
    Instead of using PIRREPORTFORMD1 7792 as a default file name for all the reports, I would like to use a field on the form for the file name. This field called PIRNO. (This field will automatically generate a number such as PIR20014-0001, PIR2014-0002 and ect. whenever a new record is added.)
    Here is an example of what I want:
    If I am currently on a record shown PIR20014-0001, then I want the file name of this report (in PDF) to be converted to PIR20014-0001 instead of PIRREPORTFORMD1 7792. I would appreciate your help a lot.

    Regards,

    Paul
    Attached Files
  • Seth Schrock
    Recognized Expert Specialist
    • Dec 2010
    • 2965

    #2
    I use the DoCmd.OutputTo method to export my reports as PDFs. This allows you to specify the report name in the OutputFile argument. Here is a link to the MSDN website explaining the command: MSDN: DoCmd.OutputTo

    Comment

    • accessbeginner
      New Member
      • Apr 2014
      • 4

      #3
      Hi Seth,
      I am new at VBA code.
      Below is the VBA code which I use to print. If you can, could you please show me how to change it? Thank you.


      Code:
      Private Sub Command265_Click()
      Dim strWhere As String
      
          If Me.Dirty Then    'Save any edits.
              Me.Dirty = False
          End If
      
          If Me.NewRecord Then 'Check there is a record to print
              MsgBox "Select a record to print"
          Else
              strWhere = "[PIRNO] = " & Me.[PIRNO]
              DoCmd.OpenReport "PIRREPORTFORMD17792", acViewPreview, , strWhere
          End If
      End Sub
      Last edited by Rabbit; Apr 29 '14, 03:46 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.

      Comment

      • zmbd
        Recognized Expert Moderator Expert
        • Mar 2012
        • 5501

        #4
        Please follow the link that Seth gave you and read how to use the command.
        Then attempt to alter your code to use the option given to you by Seth.
        If you are still not obtaining the desired results then post back.
        Normally, we're not here to write the code for you - that is somehthing you really must do for yourself or you will never benefit from the knowledge.

        -z

        Comment

        Working...