Page 2 of 2 FirstFirst 12
Results 16 to 27 of 27
  1. #16
    Join Date
    Apr 2017
    Posts
    1,680


    Quote Originally Posted by sheusz View Post
    The use of a command button is not practical in this case. There are some 30odd reports in the combo boxes. Event though only about 1/3rd of them require date criteria, I don't want a form loaded with command buttons to collect this information.
    This is why I adviced to use global variable to store the name of last report user selected from any of report combos. There will be a single command button, which will run the report which name was stored in global variable.

    Additionally (for case user forgot which report was selected), the AfterUpdate event of report combo may (along with storing report name in global variable, and setting proper filtering controls visible, and all others invisible) update the Caption property of Command Button to something like "Run Report SelectedReport".

  2. #17
    sheusz is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    May 2015
    Posts
    151
    Hi ArviL

    OK, now I understand.

    I've started working on the form idea, and have it mostly working, however I've hit a hurdle.

    The query underlying the reports has a Yes/No field called "Resovled".

    On the report selection form I have a combo box where the user can choose to display ALL records, RESOLVED records or UNRESOLVED records.

    When they select RESOLVED a variable is set to "True"

    When they select UNRESOLVED a variable is set to "False"

    When they select ALL a variable is set with no value - meaning that all records should be displayed.

    For testing purposes I have a text box on the form that shows the selection result variable (True, False or nothing). I thought that I could place the value of the text box in the query to display the matching records, but I'm encountering an error.

    This is what I have placed in the query

    Code:
    [Forms]![frmPhoneSupportReportData]![txtFilter]
    Is this correct?

  3. #18
    Join Date
    Apr 2017
    Posts
    1,680
    Simplest way:
    In AfterUpdate event of Command Button, call your report as
    Code:
    SELECT CASE Me.cbbFilterField
         CASE "All"
              DoCmd.OpenReport "YourReportName" acNormal
         CASE "True"
              DoCmd.OpenReport "YourReportName" acNormal, "Resolved = True"
         CASE "False"
              DoCmd.OpenReport "YourReportName" acNormal, "Resolved = False"
    END SELECT
    In case you need to set condition for report based on several filtering controls, it is better you save the filter string to string variable. Like
    Code:
    Dim strRepFilter As string
    ...
    SELECT CASE Me.cbbFilterField
         CASE "All"
              strRepFilter = ""
         CASE "True"
              strRepFilter = "Resolved = True"
         CASE "False"
              strRepFilter = "Resolved = False"
    END SELECT
    SELECT CASE Me.cbbnextFilterField
         ...
    END SELECT
     
    SELECT CASE strRepFilter
         CASE ""
              DoCmd.OpenReport "YourReportName" acNormal
         CASE OTHER
              DoCmd.OpenReport "YourReportName" acNormal, strRepFilter
    END SELECT

  4. #19
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    I don't think you are getting it. One combo, one command button. Date controls only appear IF the report requires them. One if only one date (e.g. a start date) two if an end and start date and none if none. In fact, you can hide the command button if you want the combo to simply open a report that does not required date inputs. You can also eliminate the command button entirely in cases where only the combo selection can control what happens, but you don't have that situation because some reports require one or more dates.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #20
    davegri's Avatar
    davegri is online now Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Here's an example. The Start Date and End Date textboxes will appear/disappear depending on the report selected in the listbox. Reports can have just Start Date, or Start Date and End Date, or No Dates required.
    Reports-sheusz-davegri-v01.zip

    Click image for larger version. 

Name:	sReports.png 
Views:	13 
Size:	58.0 KB 
ID:	50743

  6. #21
    sheusz is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    May 2015
    Posts
    151
    Hi Arvil, Micron and Davegri

    Thank you all for your replies and patience. I've got it working the way I wanted using this code;

    Code:
    Select Case Me.cmbFilter
         Case "All"
              DoCmd.OpenReport "PhoneCallsSpecifyData", acPreview
         Case "Resolved"
              DoCmd.OpenReport "PhoneCallsSpecifyData", acPreview, , "Resolved = True"
         Case "Unresolved"
              DoCmd.OpenReport "PhoneCallsSpecifyData", acPreview, , "Resolved = False"
    End Select
    So, after all of that I can now display an error message that means something in the report's NoData event !

    Code:
    Private Sub Report_NoData(Cancel As Integer)
     
        Dim message As String
        message = "Sorry, there is no data to report for the period " & _
        Forms!frmPhoneSupportReportData!txtStartDate & " and " & Forms!frmPhoneSupportReportData!txtEndDate & " for " & Forms!frmPhoneSupportReportData!cmbFilter & " records."
            
        MsgBox message, vbInformation, "No Data"
        Cancel = True
        
    End Sub
    A huge thank you to Micron and Davegri for your suggestions and samples. As a result, I'm going to totally re-work the whole Reports section of the DB, which will take some doing, but will give me a really nice result.

  7. #22
    sheusz is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    May 2015
    Posts
    151
    Hi Micron

    Thank you for all of your help. I did understand what you meant, I was just aiming to solve small problems before I tackled the redesign I'm going to perform based on your suggestions. That's a project for when I return from holidays.!

  8. #23
    sheusz is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    May 2015
    Posts
    151
    Hi Davegri

    This is awesome and has given me some great ideas. Thanks for going to the trouble of creating and sharing the code.

    The Print Both Sides checkbox has me intrigued!

    I'll still use the combo box method for report selection to keep the report selection form tidy.

    As I said to Micron, a project for when I return from holidays...

  9. #24
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    Perhaps have a look at my two example apps as well. They may help ...
    Multiple Group & Filter (isladogs.co.uk)
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  10. #25
    sheusz is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    May 2015
    Posts
    151
    Most certainly will.

    I'm always amazed by the generosity of people on this forum.

  11. #26
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Glad we could help in whatever way we can.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  12. #27
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    You're welcome
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Display a query parameter on a report
    By tfbalogh in forum Access
    Replies: 2
    Last Post: 06-30-2017, 12:54 PM
  2. Replies: 2
    Last Post: 04-04-2013, 03:13 PM
  3. Replies: 7
    Last Post: 03-10-2013, 11:29 AM
  4. Query parameter prompt - Format message
    By daved292 in forum Queries
    Replies: 2
    Last Post: 06-08-2012, 11:09 AM
  5. Display Query Value That Requires Input Parameter
    By Access::Student in forum Access
    Replies: 1
    Last Post: 05-29-2009, 08:43 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