Results 1 to 9 of 9
  1. #1
    Join Date
    Jul 2016
    Posts
    3

    Lightbulb How to print different reports in one button?

    Hi. I have a form that has a button and If a certain checkbox is checked it will print that specific report for that checkbox item. Let's say If I choose checkbox one then it will print report A, and If I choose checkbox three it will print report C. I'm not sure if that makes sense but how do I make it work?


    Thank you
    -X


  2. #2
    Eljefegeneo is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    14
    Well, you could just use something like:
    [code]
    If CheckBoxA= True then
    Command to print Report A
    If CheckBoxB = True Then
    Command to print ReportB
    ...etc.
    However, I usually have a combox that lists all the reports and then print them using the afterupdate event or a button that says print the report selected in the combo box

  3. #3
    Join Date
    Jul 2016
    Posts
    3
    Thanks. Having a combo box is actually a great idea, I've never thought of that. Can you give me a code after adding the combo box?

  4. #4
    Eljefegeneo is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    14
    Make a combobox, type in the reports you want to see. Then depending on what you want to do, use one of the following on the AfterUpdate event.
    To Print: DoCmd.OpenReport cboReportName, acViewNormal
    To View in Report View: DoCmd.OpenReport cboReportName, acViewReport
    To view in Print preview: DoCmd.OpenReport cboReportName, acViewPreview

    Or you can have three buttons on the form, one for each of the above.

    the combo box wizard will lead you through the steps to add items (reports) to the list. Just have one column. To add to the list just right click on the combobox and then edit the list.

  5. #5
    Micron is online now Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,784
    If you have many more than 3 or so, there are other ways you might want to explore. One would be to start with a query that returns the names of all reports whose checkbox selection is set to True (checked) then loop through a recordset and print out each report. Checkboxes or radio buttons or command buttons on a form could accommodate your needs, but it is a clunky way of providing the input. Each time a report is added or removed from the db, the form has to be redesigned (not good).

    If there are only a few reports, then a listbox whose multi-select property is set to true would allow you to choose several reports. AFAIK, combo boxes still do not have a multi-select property (and I would not resort to using a multi-value field to get around this). You could also loop through the selected items in a listbox, and the list would be generated by looking at a table of reports.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    As has been suggested, this all really depends on the scale of what you're doing, here...whether you're talking about a few Reports...or many Reports...or all Reports in the Database. Also, are you talking about only printing one Report at a time (per click of the button) or multiple Reports per click.

    To load the Combobox with all Reports in the db, you can use this as the RowSource:

    Code:
    SELECT MSysObjects.Name FROM MsysObjects WHERE (Left$([Name],1)<>"~") AND (MSysObjects.Type)= -32764 ORDER BY MSysObjects.Name;

    To simply print a Report from the Combobox selection you can use code like this:

    Code:
    Private Sub cboReportToPrint_AfterUpdate()
        
        If Nz(Me.cboReportToPrint, "") <> "" Then
         DoCmd.OpenReport cboReportToPrint, acViewPreview
        Else
         MsgBox ("You Must First Select a Report To Print!")
         Me.cboReportToPrint.SetFocus
       End If
       
       Me.cboReportToPrint = Null
    
    End Sub

    As mentioned by Eljefegeneoin in Post #4, you can replace acViewPreview with whatever view you want.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  7. #7
    Micron is online now Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,784
    With all due respect, I believe this select statement would also list sub reports, which I think one would not want to print (or whatever the case is) separately. It would also print the wrong report if an errant mouse click chose the wrong report. Also, I'm curious as to how one might generate a null from an update of the combo (so as to require converting it to an empty string) since an update returns a value (no selection = no update). Checking for null values in the combo box would be required if the report action was initiated from a button click though. A couple of approaches for this topic are listed here:
    http://allenbrowne.com/ser-19.html
    I like the idea of a checkbox to provide the option to open in print preview. One could use a frame and radio buttons to provide print preview, print, and report view options.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    I'll take your word for that...never had occasion to use this in a db with subreports; this has been out there for years and years.

    Clicking on the wrong item generally will result in a wrong action being taken.

    As for generating a Null from a Combobox, I'm guessing the original code came from generating a Report from a Textbox and a Command Button, and was adapted; this was simply code I had in my code archives.

    Thanks for your comments!

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  9. #9
    Join Date
    Jul 2016
    Posts
    3
    Thank you all very much for the help

    I researched even more yesterday and somehow I managed to find what I've been looking for and I cancelled the idea of printing the report right away coz it might cause a lot of damage so, I chose print preview instead. Sorry for not using the codes you all suggested. Then again, Thank you 3x

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

Similar Threads

  1. Replies: 1
    Last Post: 11-07-2015, 12:07 PM
  2. Replies: 4
    Last Post: 02-12-2014, 12:49 PM
  3. Replies: 2
    Last Post: 04-02-2012, 04:34 AM
  4. Replies: 5
    Last Post: 08-22-2011, 11:24 AM
  5. Replies: 0
    Last Post: 02-22-2011, 05:04 AM

Tags for this Thread

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