Page 1 of 2 12 LastLast
Results 1 to 15 of 28
  1. #1
    cynthiacorley is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2009
    Posts
    1

    Print a specific record report from a form


    I can't seem to print a report on the specific record that I have opened on the form. I have tried using a macro with an Open Report and WHERE condition and also tried a stored procedure. Can't seem to get either one to work. I have enclosed a very simplified version of my database and what I need to do. I'm kind of new to macros and procedures, so please provide detailed instructions. Thanks in advance for your help!

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows XP Access 2002
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Hi Cynthia,
    It seems to work just fine for me. The report is only for the selected Order_No.

  3. #3
    bbylls is offline Advanced Beginner
    Windows Vista Access 2003
    Join Date
    Dec 2009
    Posts
    33
    I am trying to do the same thing.
    I cannot open her database because it is 2007 and I am 2003.
    I would like to see the code that makes this work.
    Can you post the code for printing just the record currently on the form.
    Thank you.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922

  5. #5
    bbylls is offline Advanced Beginner
    Windows Vista Access 2003
    Join Date
    Dec 2009
    Posts
    33
    Thanks.
    It works perfect.
    Now, how can I select which printer that specific report will go to?

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Unless you are changing the printer all of the time, each report will remember which printer to use if when in design mode for the report you go to File>Print and select a printer.

  7. #7
    bbylls is offline Advanced Beginner
    Windows Vista Access 2003
    Join Date
    Dec 2009
    Posts
    33
    Yes, I would like the option to change the printer when I print a report.
    I would like the option to send it to my printer, or maybe my bosses printer, or maybe to make a pdf file.
    Thanks.

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    To do this with a macro, first you would use an OpenReport action to
    Preview the report, and then the RunCommand/Print action which will open
    the print dialog.

  9. #9
    bbylls is offline Advanced Beginner
    Windows Vista Access 2003
    Join Date
    Dec 2009
    Posts
    33
    Thanks RG
    I'll see if I can work out the code.

  10. #10
    bbylls is offline Advanced Beginner
    Windows Vista Access 2003
    Join Date
    Dec 2009
    Posts
    33
    I'm close.
    This is my code:

    Dim stDocName As String

    stDocName = "Packer"
    StrFilter = "[packer#]=" & Me.packer_

    DoCmd.OpenReport stDocName, acPreview, , StrFilter
    DoCmd.RunCommand acCmdPrint
    DoCmd.OpenReport stDocName, acNormal, , StrFilter

    I get a blank preview and the printer dialog box.
    After I select the printer, the preview then shows up and it prints 2 copies to the correct printer.
    What's missing?
    Thanks.

  11. #11
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You need to have Option Explicit at the top of your Class module and then Debug>Compile your code. It should throw an error.

  12. #12
    bbylls is offline Advanced Beginner
    Windows Vista Access 2003
    Join Date
    Dec 2009
    Posts
    33
    This is the complete code:

    Private Sub PrintPacker_Click()
    On Error GoTo Err_PrintPacker_Click

    Dim stDocName As String

    stDocName = "Packer"
    StrFilter = "[packer#]=" & Me.packer_

    DoCmd.OpenReport stDocName, acPreview, , StrFilter
    DoCmd.RunCommand acCmdPrint
    DoCmd.OpenReport stDocName, acNormal, , StrFilter

    Exit_PrintPacker_Click:
    Exit Sub

    Err_PrintPacker_Click:
    MsgBox Err.Description
    Resume Exit_PrintPacker_Click

    End Sub


    I am not familiar with all of the Access terminology as I am a newby at this, so I am not sure what you are talking about.

  13. #13
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    The top of your code module should start with these two lines:
    Option Compare Database
    Option Explicit


    Then while looking at your code go to Debug>Compile and compile your code, please.

  14. #14
    bbylls is offline Advanced Beginner
    Windows Vista Access 2003
    Join Date
    Dec 2009
    Posts
    33
    These are at the beginning of the code:
    Option Compare Database
    Option Explicit

    I ran the debug and found a missing line.

    I have been playing around and not had any luck.
    I have a form with a button on it that I want to print the current record on a report.
    Using the following code, I get a blank preview and the printer select dialog box, I choose the printer I want to print the report on, but the report prints on the default printer, and the form prints on the selected printer.

    Code:
    Private Sub PrintPacker_Click()
    On Error GoTo Err_PrintPacker_Click
    
        Dim stDocName As String
        Dim StrFilter As String
        
        stDocName = "Packer"
        StrFilter = "[packer#]=" & Me.packer_
        
        DoCmd.RunCommand acCmdPrint
        DoCmd.OpenReport stDocName, acPreview, , StrFilter
        DoCmd.OpenReport stDocName, acNormal, , StrFilter
    
    Exit_PrintPacker_Click:
        Exit Sub
    
    Err_PrintPacker_Click:
        MsgBox Err.Description
        Resume Exit_PrintPacker_Click
        
    End Sub
    I think I am close, but just don't have the knowledge to finalize it.
    Please help.
    Thanks

  15. #15
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Try:
    Code:
    Private Sub PrintPacker_Click()
    On Error GoTo Err_PrintPacker_Click
    
        Dim stDocName As String
        Dim StrFilter As String
        
        stDocName = "Packer"
        StrFilter = "[packer#]=" & Me.packer_
        
        
        DoCmd.OpenReport stDocName, acPreview, , StrFilter
        DoCmd.RunCommand acCmdPrint
    '    DoCmd.OpenReport stDocName, acNormal, , StrFilter
    
    Exit_PrintPacker_Click:
        Exit Sub
    
    Err_PrintPacker_Click:
        MsgBox Err.Description
        Resume Exit_PrintPacker_Click
        
    End Sub

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. print continued at bottom of report
    By ecpike in forum Reports
    Replies: 2
    Last Post: 02-25-2010, 02:50 PM
  2. Print Report from Form ID
    By Brian62 in forum Forms
    Replies: 1
    Last Post: 09-18-2009, 01:50 PM
  3. Replies: 1
    Last Post: 07-30-2009, 12:54 PM
  4. Print a different image per record
    By mcaldwell in forum Reports
    Replies: 5
    Last Post: 04-24-2009, 02:00 PM
  5. Replies: 3
    Last Post: 03-24-2006, 08:40 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