Results 1 to 5 of 5
  1. #1
    usmcgrunt's Avatar
    usmcgrunt is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2010
    Location
    Just outside the gates of freedom
    Posts
    71

    Combo box to select report to Print

    I created a form where the user selects a report from the combo box to print. The code I am usings is:

    DoCmd.OpenReport Me.cboSelectException, acPreview

    Me.cboSelectException is the name of the report in the bound field of the unbound combo box.

    All works as it should.

    Now the tricky part, at least for me is trying to print all the reports from the combo box.

    I thought I could add an ALL selection in the combo box but I am clueless as to what the code might look like.



    I also thought I could create a macro with all of the reports in it and add some IF - THEN - ELSE code to make this work. No joy.

    Suggestions?

    Thanks, Sean

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    I believe one thing you can do in a query statement is write:
    Code:
    SELECT "Select All", field1, field2, etc...
    If I remember right, that creates a field with that name but does nothing else. If that does work, you can use it to add the option to the box. Then of course though, you'll have to code the loop to print all the reports yourself.

  3. #3
    usmcgrunt's Avatar
    usmcgrunt is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2010
    Location
    Just outside the gates of freedom
    Posts
    71
    Adam, thanks for the suggestions.

    Would I use your query statement in place of the row source code I have below?

    I have in the unbound combobox (cboSelectException) row source the following:

    All;"All Exception Reports";rptMissingEdObj;"Missing Educational Objectives";rptMissingLearnOut;"Missing Learning Outcomes";rptMissingLessonReferences;"Missing References";rptMissingSupport;"Missing Support Requirements"

    All of the titles that begin with 'rpt' are the actual report names. The titles in "" are the names that are visible in the combobox. The first entry in Blue is the one that I am trying to figure out.

    I know it is not correct but it is a place holder until I can figure out what should go there.

    This is code that I currently have on the button. I have no idea what to put in to get all of the reports to print as well as individual reports to print.

    ' ************************************************** *************************
    ' When the user presses this button the selected Exception Report is printed.
    ' ************************************************** *************************

    Private Sub btnPrintLC_Click()
    On Error GoTo btnPrintLC_Click_Err

    DoCmd.OpenReport Me.cboSelectException, acNormal
    btnPrintLC_Click_Exit:
    Exit Sub
    btnPrintLC_Click_Err:
    MsgBox Err.Description
    Resume btnPrintLC_Click_Exit
    End Sub

    -----------------------------------------------------------------
    Sean

  4. #4
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    using ALL is just fine. you simply have to make up for it with a conditional in code. Like so:
    Code:
    if me.combo = "ALL" then
       'loop through reports here
    else
       'do what you're currently doing
    end if
    looks like you're using the default printing that happens when you open the reports in normal view? Sorry about that! I gave you wrong advice! Allen Browne might be able to help print in VBA: http://www.allenbrowne.com/AppPrintMgt.html

    I also saw this:
    Code:
    DoCmd.RunCommand acCmdPrint
    you could use that in your loop, but I've never used it so I don't know if it gives you a dialog everytime or not.

  5. #5
    usmcgrunt's Avatar
    usmcgrunt is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2010
    Location
    Just outside the gates of freedom
    Posts
    71
    Adam, udaman! It works!! Thanks. I am still working the code to prevent all of the print dialogs from showing up but since I only have 4 reports in the "All" category it might not be such a big deal.

    And from the looks of this post it may not be possible unless I want to create a hidden from with a timer event to suppress the print dialog. A lot of posts reference this post as an option.

    http://www.mvps.org/access/api/api0037.htm


    My solved Code is below. Thank for your help.

    ' ************************************************** *************************
    ' When the user presses this button the selected Exception Report is printed.
    ' ************************************************** *************************

    Private Sub btnPrintLC_Click()
    On Error GoTo btnPrintLC_Click_Err

    Dim strReport2 As String
    Dim strReport3 As String
    Dim strReport4 As String
    Dim strReport5 As String

    strReport2 = "rptMissingEdObj"
    strReport3 = "rptMissingLearnOut"
    strReport4 = "rptMissingLessonReferences"
    strReport5 = "rptMissingSupport"

    If Me.cboSelectException = "All" Then

    DoCmd.OpenReport strReport2, acNormal
    DoCmd.OpenReport strReport3, acNormal
    DoCmd.OpenReport strReport4, acNormal
    DoCmd.OpenReport strReport5, acNormal

    Else

    DoCmd.OpenReport Me.cboSelectException, acNormal

    End If

    btnPrintLC_Click_Exit:
    Exit Sub

    btnPrintLC_Click_Err:
    MsgBox Err.Description
    Resume btnPrintLC_Click_Exit

    End Sub

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

Similar Threads

  1. Combo boxes both primary keys to select record
    By Alexandre Cote in forum Forms
    Replies: 3
    Last Post: 08-10-2010, 07:11 AM
  2. Replies: 47
    Last Post: 06-17-2010, 03:04 PM
  3. Print Report from Form ID
    By Brian62 in forum Forms
    Replies: 1
    Last Post: 09-18-2009, 01:50 PM
  4. Combo-box to select item to edit in Form
    By DHavokD in forum Forms
    Replies: 7
    Last Post: 06-05-2009, 01:39 PM
  5. Combo box select from two fields
    By cnestg8r in forum Access
    Replies: 0
    Last Post: 10-31-2008, 10:05 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