Results 1 to 8 of 8
  1. #1
    krasbauer is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2015
    Posts
    4

    Print report of the selected form record [Solved]

    Hi !

    So i have a form where i fill some parameters and a report is generated

    My probleme is, am using a printing button, that show all the reports plus a printing options window where i have to chose the number of the report i want to print

    For instance if i want to print the record 122 i would have to see the difference between the last record and the 122....for instance 130-122= 8, so i print the 9th page.

    You might have noticed how annoying that is ! what i want is a button that automatically prints the report of the form record am currently on or selecting...or maybe one that asks for the Primary key of the record to print its report.



    Thank you
    Last edited by krasbauer; 12-04-2015 at 09:41 AM.

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    You can use VBA to apply criteria to the Filter property of a report and send it directly to the printer. You just need to define the criteria using variables, like values of controls in your form.

    So something like
    Code:
    DoCmd.OpenReport "ReportName", , , "FieldName='" & Me.ControlName.Value & "'"
    'or for Numeric
    DoCmd.OpenReport "ReportName", , , "FieldName=" & Me.ControlName.Value & ""

  3. #3
    krasbauer is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2015
    Posts
    4
    Hi !
    Thanx for the tip, so i was working on something very similar :

    Code:
    DoCmd.OpenReport "rptEmployeeDetails", acViewPreview, , _
                     "[lngEmpID]=Forms!frmEmployee!lngEmpID"
    anything i need to correct ? and by the way how do i add this vba to a button all i can add to buttons are macros !

    Thanx again

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    That looks good to me. You can create a Click Event sub procedure from the Property Sheet while in design view of your form. With the command button selected, look under the Event tab of the property sheet. Locate the On Click event and click on the ellipses. Then, select Code Builder. The VBA editor will open and place your cursor where your code needs to be placed. Place your code just before the End Sub termination line.

    Here is a picture of the ellipses button for adding a RowSource to a combo. You want the On Click event under the Event tab.
    Click image for larger version. 

Name:	QueryBuilderCombo.jpg 
Views:	17 
Size:	51.9 KB 
ID:	22926

  5. #5
    krasbauer is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2015
    Posts
    4
    HI !

    It worked perfectly ! i just click and it automatically prints the report of the record shown on screen !

    Code:
    Private Sub Aperçu_certificat_Click()
    
    DoCmd.OpenReport "Certificat_phytosanitaire_importation", , , _
                     "[N°]=Forms!Formulaire_certificats_phytosanitaire!N°"
                     
    End Sub
    Ok so my next question is how do i make it print 2 copies instead of just one
    And by the way dude, many thanks ! that helped a lot !

    PS : i noticed that command has an open argument possibility at the end, so i can add a copies=4 i guess ?

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by krasbauer View Post
    ...how do i make it print 2 copies...
    Duplicate the code that is within the click event sub procedure. As an example ...
    Code:
    Private Sub Aperçu_certificat_Click()
    DoCmd.OpenReport "rptEmployeeDetails", acViewPreview, , _
                     "[lngEmpID]=Forms!frmEmployee!lngEmpID"
    
    DoCmd.OpenReport "rptEmployeeDetails", acViewPreview, , _
                     "[lngEmpID]=Forms!frmEmployee!lngEmpID"
    End Sub
    If you need to print more than two copies, like 4 or more copies, I would recommend using code that fires a single statement multiple times. So that code would look different if you need to print many copies.

    .

  7. #7
    krasbauer is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2015
    Posts
    4
    Hahahaha thats what i did thanx by the way, and sorry for the trouble !

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    No trouble at all and welcome to the forum.

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

Similar Threads

  1. How to print selected records of a Report
    By Fyeung in forum Reports
    Replies: 3
    Last Post: 02-16-2015, 07:43 PM
  2. Print only selected record of a sub form
    By falahsalih in forum Access
    Replies: 10
    Last Post: 05-11-2014, 09:28 AM
  3. Replies: 3
    Last Post: 02-11-2013, 04:43 PM
  4. How to Print Selected Record
    By indranx in forum Reports
    Replies: 2
    Last Post: 05-31-2011, 09:54 PM
  5. Replies: 2
    Last Post: 09-18-2010, 07:52 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