Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    mnsemple83 is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Posts
    40

    Applying a parameter query to several queries to create a report.

    Good evening to everyone!



    I am currently working on a database system and I am trying to figure out a way to allow a user to create a report based on two values: a patient's unique identifier and their date of visit to the hospital. The purpose of this report will allow to view all patient data for that particular date.

    I already created a report that consists of several subreports that were generated by queries. However, not all queries function the same. For example, I created three queries that display the 4 most recent entries prior to a date value submitted by the user. For another query, I programmed it to return all entries for a specified date and beyond.

    My solution was to create a parameter query that will instruct the database to create a report based on the patient's identifier and specified date value. I just need to know how I can apply one date value in a query to several queries at the same time. (I highlighted that last sentence in bold because that is the main problem).

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Queries cannot refer to each other's input paramters. Input parameters obtained by prompting the user are next to impossible to validate. Bad input and the report still tries to run but results will be unsatisfactory.

    Have user select/enter values in controls on a form. Queries refer to the controls on form as their input parameters.
    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.

  3. #3
    mnsemple83 is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Posts
    40
    I designed a form that allows the user to enter those values. I am thinking about designing a query that will allow the user to apply those values to several fields within that query. Is that possible and how would that work?

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    The user input on form is for filter criteria? In the criteria cell for each field, reference the appropriate control on the form. Syntax like:
    Forms!formname!controlname
    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.

  5. #5
    mnsemple83 is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Posts
    40
    I created my parameter query with a combo box and two buttons, applied it to the criteria section for the field I am interested in querying. However, when I run the query, the form does not open up like it should. Here is my code:

    [Forms]![frmGetPatientMRN]![MRN]

    What am I doing wrong?

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    You have a form with a combobox and two buttons where users enter criteria and button click opens another form bound to the query with the combobox as parameter? Show the query SQL statement for analysis.
    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.

  7. #7
    mnsemple83 is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Posts
    40
    Here is the SQL query I used:

    [Forms]![frmGetPatientMRN]![MRN]

    Now, I have decided that I'm going to use this form to obtain a patient's MRN before I print a report. In the database, the user is going to click a button called "Print Report", this will open the form that will prompt the user to select an MRN. After the user selects the MRN, several prompts will appear asking the user to enter parameters that will be used to create the report. Once the user has entered all the parameters, the report will appear in preview form and the user will be allowed to print.

    What I want to do is to use the 'frmGetPatientFrm' to select an MRN to be used in the report. The problem I am having is getting it to retrieve the MRN from the Patient's table, which is what the report is based on. The MRN is shared by the other subreports that were created from the queries.

    What methods do you suggest for accomplishing this? I already tried several.

  8. #8
    mnsemple83 is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Posts
    40
    Here's a better understanding of what I am working with:

    tblPatients - the source of the MRN (a unique identifider for each patient).
    frmGetPatientMRN - the form that is used to select the MRN from tblPatients to be used in the report.
    rptFullPatient - uses MRN from frmGetPatient to display data related to that patient.

    I know that I have to write the code for the form in the Open event of the report. It's just a matter of trying to get it to work correctly. I will let you know if I have any other problems.

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    No, I don't think Open event of report is best way to open filtered report (I have used that only once). Following are the two ways I routinely use to filter report, and No. 1 is my preference.

    1. DoCmd.OpenReport "reportname here", , , "MRN=" & Me.MRN
    This code would be behind an event of frmGetPatientMRN, perhaps a button click.
    This code utilizes the WHERE argument of DoCmd.OpenReport and will restrict the report to retrieve records that only meet the criteria.

    2. Set input parameters in the query that the report is bound to. In the criteria row of query in design view, refer to the control on frmGetPatientMRN with: Forms!frmGetPatientMRN!controlname
    Now either open the report manually from the navigation pane or with code in event, such as button click.

    [Forms]![frmGetPatientMRN]![MRN] is not an SQL statement, it is only a reference to form control/field. A very basic SQL statement would look like: SELECT * FROM tablename;

    If you want to post an extract of relevant objects from your project (no actual data needed) I will look at.

    Here is another recent thread on this topic https://www.accessforums.net/forms/r...ies-15956.html
    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
    mnsemple83 is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Posts
    40
    I changed a few things since my last post:

    1. The form is no longer called "frmGetPatientMRN"; it is now called "frmReportData" because it's more descriptive.
    2. The form will not only get a patient's MRN but allow the user to enter a specific date for the data that they are interested in. This date value will be used in two subqueries.

    Also, the report I have created is not based on a query, but on the Patient's table ("tblPatients"). The MRN field in that table is obtained by the subqueries that are used to create the subreports. Should I be using a query instead or will this work with the tables as well?

  11. #11
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Option 1 can work with table as report RecordSource.

    Option 2 requires a query as report RecordSource.
    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.

  12. #12
    mnsemple83 is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Posts
    40
    I was able to get the report to display data based on the MRN that was submitted through the form, but now I am trying to get the queries for the subreports to display data based on the date value entered on the form. I tried manipulating the subreport by writing an SQL query in the VBA for the form and that did not work. What I am trying to say is that I want to use this value in the queries that create the subreports within the main report.

    Any ideas?

  13. #13
    mnsemple83 is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Posts
    40
    I have discovered a solution to the problem.

    What I did with the date value is that I entered the following code in the date field for several queries:

    [Forms]![frmReportData]![DateOfVisit]

    Now, when I enter a date value in the form, it applies to all the queries. I wonder why it didn't work before.

    Thanks June7 for your advice. It defintiely helped!

    - mnsemple83

  14. #14
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    How did you envision manipulating subreport by writing an SQL query in VBA?
    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.

  15. #15
    mnsemple83 is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Posts
    40
    Quote Originally Posted by June7 View Post
    How did you envision manipulating subreport by writing an SQL query in VBA?
    I was planning on writing a SELECT query inside the OnClick Event for the "OK" button. That way, the data will be retrieved by the database and used in the report.

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

Similar Threads

  1. Replies: 3
    Last Post: 02-15-2011, 05:24 AM
  2. Replies: 3
    Last Post: 05-21-2010, 03:57 PM
  3. Query Parameter not udpating Report
    By krutoigoga in forum Reports
    Replies: 9
    Last Post: 04-30-2010, 06:46 AM
  4. Report with Parameter Query/Form
    By maggioant in forum Reports
    Replies: 0
    Last Post: 10-09-2009, 09:48 AM
  5. Replies: 6
    Last Post: 02-20-2009, 11:50 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