Results 1 to 8 of 8
  1. #1
    lzook88 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    75

    Question Two Queries / One Report


    Here I go at trying to explain this.. I have two queries. The first one pulls all records between two dates entered on a form. The second one then takes that date and counts the number of times each item appears. Then I have a report that lists out the data from the second query.

    Query 1 (qryTransfersBetweenDate1ANDdate2)
    INAME (Name of item from tblProducts)
    OldLocation (Where the item was transferred from, from tblTransfers)
    DateTransferred (The date the item was transferred, from tblTransfers)

    Query2 (qryTransfersCountBetweenDate1ANDdate2)
    ProductName Field (IName from Query1)
    NumberOfDups (Count field to count all items from Query1 (NumberOfDups: IName)

    Report (Yearly)
    Product Name
    Number of Dups

    Form (Yearly Transferred)
    Start Date
    End Date

    The idea is that you would enter the Start Date and End Date on the form. It would update Query 1 with those dates. Then the report would open and be sorted down to those results.

    All the queries work.. The issue I am having is when I try to add in the form with the dates I want to use. These dates can change based on what the user is trying to look at.

    I tried using this code in the Form's submit button:

    Code:
    DoCmd.OpenQuery "qryTransfersBetweenDate1ANDdate2", acViewNormal
    DoCmd.ApplyFilter , "tblTransfers.[Date Transferred] Between #" & Me.StartDate & "# And #" & Me.EndDate & "#"
    
    DoCmd.OpenReport "Yearly", acViewReport, , , acDialog
    Any help would be greatly appreciated.

    Thanks,
    Z

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Not sure it is what you are after, but you can apply criteria to a Report's Filter property when opening the report via DoCmd.

    DoCmd.OpenReport "Yearly", acViewReport, , "Between #" & Me.StartDate & "# And #" & Me.EndDate & "#"

  3. #3
    lzook88 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    75
    I run the report off the second report. So there is no connection to the first query. The dates don't show up on the actual report.

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Hmmm, well, I can say with confidence that you can do something better with your variables than using them as a filter for your table. So maybe you can use them in a query if you do not want your report to use the variables. Not too sure where else you could possibly use the variables.

  5. #5
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Let me see if I understand:

    1) You have a form with two text controls that have dates entered and a button that opens the Report.
    2) Query1 (qryTransfersBetweenDate1ANDdate2) has the dates in the criteria for field "DateTransferred"
    (criteria for "DateTransferred" looks like Between Forms!FormName.Date1 and Forms!FormName.Date2 )
    3) Query2 (qryTransfersCountBetweenDate1ANDdate2) used query1 as the source (Query2 is a totals query?)
    4) Report "Yearly" is bound to Query2 (qryTransfersCountBetweenDate1ANDdate2)

    You enter the dates in the two controls, then click the button.
    Other than validation code (check for proper dates or no data), I would think the code to open the report would be
    Code:
    DoCmd.OpenReport "Yearly", acViewReport
    Query1 does all of the "filtering", so now "filter" needs to be set.


    Am I close?

  6. #6
    lzook88 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    75
    " Between Forms!FormName.Date1 and Forms!FormName.Date2 " you have found the fix.. I knew it had to be something simple. This should work perfectly doing it this way.


    When adding it to my query I found it should be:
    Between Forms!FormName
    !Date1 and Forms!FormName!Date2

    Thanks,\
    Z

  7. #7
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Sometimes the dot works, sometimes need to use the bang.

    You DID change "FormName" to your form name.... right???

    Glad you figured it out.....

  8. #8
    lzook88 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    75
    Yeah. I did that.. I'm not that big of a noob with this stuff.. Just have an occasional brain fart and cant remember my head from my backside. :-) and I turn to here to get my head situated back on my shoulders and out of my rear!

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

Similar Threads

  1. Replies: 11
    Last Post: 04-07-2015, 09:15 AM
  2. using two queries in a report
    By Alliana Gray in forum Access
    Replies: 9
    Last Post: 08-18-2011, 05:55 PM
  3. Two queries in one report
    By victor in forum Programming
    Replies: 1
    Last Post: 08-05-2010, 01:31 AM
  4. Replies: 1
    Last Post: 06-29-2010, 03:40 AM
  5. Replies: 3
    Last Post: 05-21-2010, 03:57 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