Results 1 to 8 of 8
  1. #1
    PeakH is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2017
    Posts
    143

    Select Report from combobox always brings up same report regardless of selection

    On my Main Menu, I have a combobox listing a couple reports. The goal is to select a report and then click a button to open it.

    The combobox (called ReportList) record source is table [T-ReportList] so that the user selects the ReportName

    ReportName ObjectName ListOrder
    Monthly Sales R-Monthtodatesales 1
    Monthly Samples R-Monthtodatesamples 2

    There is no Control Source since I don't need this saved anywhere.

    The view report button has this on click event



    Code:
    Private Sub OpenReports_Click()
    DoCmd.OpenReport DLookup("[ObjectName]", "[T-ReportList]", [ReportName] = [Forms]![Main Menu]![ReportList]), acViewReport
    End Sub
    The problem is that the button always and only brings up "R-MonthtodateSales" even if nothing has been selected or if I have selected Monthly Samples.

  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,518
    Your syntax is off, but why not just use the combo? Try

    DoCmd.OpenReport Me.ReportList.Column(1), acViewReport

    which should pull object name column.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    PeakH is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2017
    Posts
    143
    What do you mean use the combo?

    I don't know enough about syntax to tell how it's off. I basically had to look up every quotation mark and comma in that one line.

  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,518
    Did you try what I suggested? Here's more on the syntax:

    DLookup Usage Samples

    But that's an extra trip to the data, when the info you want is in the combo.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    PeakH is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2017
    Posts
    143
    For what you suggested, would I replace what I currently have with that?
    That is what I tried, but it wouldn't open any report at all.

    Thanks for the link! Did I just miss the quotation marks around the criteria?

  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,518
    Yes, that would replace what you currently have. Is the combo on the same form as the code? You said the combo row source was the table, right? What is the Column Count property of the combo?

    As to the DLookup(), you missed the quotation marks and the concatenation.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    PeakH is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2017
    Posts
    143
    Ah hah! The column count was only 1. I actually had the row source as only the ReportName and ListOrder. So I added the ObjectName as column 2 so that it mimics the table, and now it works like a charm!

    Thank you very much!

    Also, what is the concatenation?

  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,518
    Happy to help! The concatenation is the second one (with delimiters, since the value is text):

    "[ReportName] = [Forms]![Main Menu]![ReportList]"
    "[ReportName] = '" & [Forms]![Main Menu]![ReportList] & "'"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 3
    Last Post: 01-20-2017, 02:25 PM
  2. Replies: 2
    Last Post: 08-22-2014, 01:20 PM
  3. Replies: 5
    Last Post: 04-09-2014, 06:57 PM
  4. emailing a report based on a combobox selection
    By ecalvert47462 in forum Access
    Replies: 9
    Last Post: 12-11-2013, 12:52 PM
  5. Replies: 0
    Last Post: 08-24-2010, 06:38 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