Results 1 to 5 of 5
  1. #1
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727

    print record


    All; using 2010. I have a form with multiple subforms link to the main form. I need to put a print button on the form for the user to print the current record they have filtered to. I want the print out to be some what organized like a report rather than a printscreen. Haven't done this before; should I create a report with the subforms? If so; can anyone suggest vba code to print preview then print if necessary? Thanks

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    The following code should help if the user is using the filter tool.

    Code:
    'Assuming the report name is rptSample
    Dim strFilter As String
    strFilter = Me.Filter 'Save the current filter parameters to a string
    'This will give you ability to Preview
    DoCmd.OpenReport "rptSample", acViewPreview, , strFilter
    'This should send it to the printer
    DoCmd.OpenReport "rptSample", acViewNormal, , strFilter

  3. #3
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    Yipes; It trys to print all the records in the DB!! Clearly I did something wrong but what?

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by slimjen View Post
    Yipes; It trys to print all the records in the DB!! Clearly I did something wrong but what?
    If the Button resides on the main form and the filtered form is the subform then you will need to get the subform's filter. My bad. The code I posted above grabs the filter for whatever form the control resides in.

    Build a report based on the same Access Query or Table your subform is based on. Assuming it is your subform that is getting filtered.

    Then you can use this revised code. Another way to get the subform's Filter is Forms!MainFormName!SubFormName!Form.Filter. The example below uses Me. and then the subform name then .Form.Filter

    'Assuming the report name is rptSample
    Dim strFilter As String
    strFilter = Me.SubFormName.Form.Filter 'Save the current filter parameters to a string
    'This will give you ability to Preview
    DoCmd.OpenReport "rptSample", acViewPreview, , strFilter
    Last edited by ItsMe; 10-07-2013 at 01:59 PM. Reason: Deleted some text

  5. #5
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    Got it. I reference the record I was trying to print in the query for the report. Works perfectly like i wanted. thanks to all for your help. This forum is awesome!!

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

Similar Threads

  1. How to print only one record
    By Mobile in forum Access
    Replies: 10
    Last Post: 06-19-2013, 01:33 PM
  2. Search,Print and Add new Record
    By Rauf in forum Forms
    Replies: 3
    Last Post: 05-20-2013, 02:07 PM
  3. Replies: 5
    Last Post: 10-26-2011, 02:59 PM
  4. How to Print Selected Record
    By indranx in forum Reports
    Replies: 2
    Last Post: 05-31-2011, 09:54 PM
  5. Print a specific record
    By NISMOJim in forum Forms
    Replies: 5
    Last Post: 01-28-2011, 04:32 PM

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