Results 1 to 13 of 13
  1. #1
    james28 is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2014
    Posts
    92

    Open Report Based on Combobox


    Hello All!


    I have a very simple setup.


    1 Form with a combobox. The combobox has 3 options: Report A, Report B, and Report C.

    The form also has a command button.


    I have 3 different reports created: ReportA, ReportB, and ReportC.




    I would like for the correct report to open, based on the selection of the combobox at the time of clicking submit.


    I know an if statement of some kind will be required. Could anyone please point me in the correct direction?


    Thank you in advance!

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    If the combo contains actual report names:

    DoCmd.OpenReport Me.ComboName
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    james28 is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2014
    Posts
    92
    Paul,

    Thank you for the prompt reply. That is a simple yet elegant solution. Currently, my report names do not align exactly the same, because the reports have 4 words each in the title.

    Is there anyway to do it if they do not match?


    Thank you again!

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Certainly, you have to use If/Then or Select/Case to examine the selected item and open the appropriate report.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    james28 is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2014
    Posts
    92
    Paul,

    Thank you again for the prompt reply.


    I have tried to create a nested iif, but it does not seem to be working. Do you happen to see anything that I am missing?



    IIf([forms]![testform]![ComboName]="Report A Long Name",DoCmd.OpenReport "ReportA", acViewReport, IIf([forms]![testform]![ComboName]="Report B Long Name",DoCmd.OpenReport "ReportB", acViewReport,DoCmd.OpenReport "ReportC", acViewReport))

    Thank you again!

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I wouldn't use IIf(), I'd use If/Then in VBA in either the after update event of the combo or behind a button.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    Dubai
    Posts
    614
    @Paul
    DoCmd.OpenReport Me.ComboName
    Just for curiosity, irrespective of the report names ( like 2 or 4 words in title as mentioned by OP), why can't your first solution work ?

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    That solution would only work if the combo contained the actual report name. If the combo has "Forum Post Report" and the report to be opened is named "rptForumPosts" obviously the code would fail. It does occur to me that the combo could have a second hidden column with the actual names in it.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Consider:

    DoCmd.OpenReport "Report" & Switch(Me.[ComboName] = "Report A Long Name", "A", Me.[ComboName]="Report B Long Name", "B", Me.[ComboName]="Report C Long Name", "C"), acViewReport

    Or with the hidden column as Paul suggested - column index begins with 0:

    DoCmd.OpenReport Me.ComboName.Column(x), acViewReport

    Why 3 reports - are they completely different in structure not just different filter criteria?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    james28 is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2014
    Posts
    92
    June,

    Thank you for the reply. Yes, all 3 reports are very different in structure, so I figured the easiest way would be to just create 3 different reports, especially since I can not have more than one detail section.

    I am not sure how to add a hidden column, so I will try the first version that you suggested. I will report back shortly! Thank you again.

  11. #11
    james28 is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2014
    Posts
    92
    June,

    Following back up. That works perfectly. Thank you!

  12. #12
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Maybe subreports would serve your requirement.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  13. #13
    james28 is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2014
    Posts
    92
    June,

    Thanks again. Subreports is exactly what I am going to try.

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

Similar Threads

  1. emailing a report based on a combobox selection
    By ecalvert47462 in forum Access
    Replies: 9
    Last Post: 12-11-2013, 12:52 PM
  2. Open Report From a ComboBox
    By tcheck in forum Access
    Replies: 5
    Last Post: 07-09-2013, 02:36 PM
  3. Replies: 1
    Last Post: 01-24-2013, 12:52 AM
  4. Replies: 1
    Last Post: 05-31-2012, 01:01 PM
  5. open form based on combobox
    By bigmac in forum Forms
    Replies: 3
    Last Post: 04-09-2012, 11:25 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