Results 1 to 6 of 6
  1. #1
    Russellh is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    68

    How do pull records based on input and input-1

    I need to be able to query the service dates for the bill. So I can query 1509 for the .billYYMM and .readdate and it will give me the TO Date. How do I in the same query tell the query to subtract 1 from the BillYYMM that I just entered and give me the read date for that field in that query?
    So Query 1 MBRHISTDETL.BILLMOYR and in the criteria box use [Enter the Bill Month Year YYMM you want to search for] will allow me to run the query at any time for any bill month year that I enter. So another field in that query is MBRHISTDETL.READDATE.


    So to get the FROM date and the TO date i need the following MRBHISTDETL.BILLMOYR (whatever I enter as input) and MBRHISTDETL.READDATE that corresponds and then I need [MRBHISTDETL.BILLMOYR]-1 and MBRHISTDETL.READDATE. The first gives me the TO date and the 2nd gives me the FROM date?

    Any idea on how to begin that?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    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
    Russellh is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    68
    Quote Originally Posted by June7 View Post
    The get another value for a field in a different record on the same table is the right way to go. I'm not familiar enough with SQL statements to translate that into what I need. But I need 2 read dates. One would be the read date with BILLMOYR of 1509 (entered from user input) and the READ DATE field that would show on the record and then the read date field that would show if I entered the BILLMOYR -1 or 1508 for the same account number.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Is it a certainty that the BILLMOYR value will be sequential, no gaps, so that -1 will always work (exception would be the very first record for each account).

    If all you want is the value to show up on a form for the current record, a DLookup() in textbox ControlSource could accomplish that.

    DLookup("ReadDate", "MBRHISTDETL", "BILLMOYR=" & Me.tbxBILLMOYR - 1)

    But domain aggregate functions can be slow performers in textbox and in queries. So if you want this output in a report, the query method is best.

    Another query approach is to build query that calculates a field for the user input value.

    SELECT *, BILLMOYR + 1 AS MatchMOYR FROM MBRHISTDETL;

    Now build another query that joins the original dataset to this query by linking on BILLMOYR and MatchMOYR fields. Could try this second query as the form's RecordSource. I am wondering if the query will be not editable for the fields from the original dataset.
    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
    Russellh is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    68
    Quote Originally Posted by June7 View Post
    Is it a certainty that the BILLMOYR value will be sequential, no gaps, so that -1 will always work (exception would be the very first record for each account).

    If all you want is the value to show up on a form for the current record, a DLookup() in textbox ControlSource could accomplish that.

    DLookup("ReadDate", "MBRHISTDETL", "BILLMOYR=" & Me.tbxBILLMOYR - 1)

    I believe this is similar to the query inside of a query. 2 queries have already been built to just produce the last payment amount and date. I am worried that by the time I am through getting the 12 fields I need from only 2 tables I will have 10 querries stacked or linked together. That would make for a troubleshooting nightmare would it not?

    But domain aggregate functions can be slow performers in textbox and in queries. So if you want this output in a report, the query method is best.

    Another query approach is to build query that calculates a field for the user input value.

    SELECT *, BILLMOYR + 1 AS MatchMOYR FROM MBRHISTDETL;

    Now build another query that joins the original dataset to this query by linking on BILLMOYR and MatchMOYR fields. Could try this second query as the form's RecordSource. I am wondering if the query will be not editable for the fields from the original dataset.


    I believe this is similar to the query inside of a query. 2 queries have already been built to just produce the last payment amount and date. I am worried that by the time I am through getting the 12 fields I need from only 2 tables I will have 10 querries stacked or linked together. That would make for a troubleshooting nightmare would it not?

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Have I misunderstood requirement? I thought you just want to get a single value from another record. Are you wanting to filter on a range?

    I don't use dynamic parameterized queries. I prefer to use VBA to build filter criteria and apply to form or report either when the object opens or by setting Filter and FilterOn properties.

    http://www.allenbrowne.com/ser-62.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.

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

Similar Threads

  1. Replies: 1
    Last Post: 11-04-2014, 12:07 PM
  2. SELECT Records based on user input
    By Mattrob in forum Queries
    Replies: 1
    Last Post: 10-10-2013, 12:28 AM
  3. Input Forms - How To Input Multiple Fields/Records?
    By butterbescotch in forum Forms
    Replies: 1
    Last Post: 04-04-2013, 06:30 AM
  4. Selecting records based on criteria from user input
    By shabbaranks in forum Programming
    Replies: 1
    Last Post: 01-04-2012, 09:06 AM
  5. Replies: 2
    Last Post: 08-09-2010, 06:34 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