Results 1 to 8 of 8
  1. #1
    gbleslie029 is offline Novice
    Windows XP Access 2003
    Join Date
    Jan 2016
    Posts
    2

    Entering specific criteria in a query to calculate a future date


    I am relatively new to Access and would like some help please. I am ok with the cosmetics but when it comes to criterion/VB etc it is a different story.

    I have created a query based on a table and need to enter a criteria to calculate 77 days in advanced based on a field in the query.

    The name of the field that I want to look at is Start_Date and I want to enter the criteria in the criteria for a field named Review_Date, which will return the date 77 days in advance.

    Maybe I shouldn't be doing this in a query, maybe I should be entering something in a form field. To be truthful I really dont know.

    Your help would be appreciated.

    G

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    yes, use a query.
    youd have a form, with a text box,...txtStartDate
    (maybe even a text box for #days....txtDays)
    the function is DateAdd("d",77,startdate)
    the query will have start date,and Target Date

    select forms!frmQry!txtStartDate, DateAdd("d",forms!frmQry!txtDays,forms!frmQry!txtS tartDate) as TargetDate

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Not really sure what you mean by 'enter a criteria'. Is Start_Date a field in table that user inputs value?

    If you just want to calculate the Review_Date, try:

    SELECT *, [Start_Date] + 77 AS Review_Date FROM tablename;

    If you want to apply filter criteria to only show records where current date is => Review_Date, try:

    SELECT * FROM tablename WHERE [Start_Date]+77 <= Date();


    Users should not interact directly with tables and queries, only forms and reports.
    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.

  4. #4
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Sounds like G wants to use criteria in the criteria row for a calculated field, which I'm pretty sure you cannot.
    I want to enter the criteria in the criteria for a field named Review_Date, which will return the date 77 days in advance.
    As noted, one can filter records on the Start_Date value and calculate the corresponding date that is 77 days later. No argument that a criteria input form is less error input prone if done right; the lowly parameter query works too (for some)

    which will return the date 77 days in advance
    Or maybe this is the calculated field and there's no criteria to be applied to it?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Yes, filter criteria can be applied to a Calculated type field.
    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.

  6. #6
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    I thought you'd end up with a sort of 'circular reference' - i.e. the criteria is unknown because it depends on the calculation which depends on the criteria...
    Thanks.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    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 would the calculated field depend on the filter criteria? It's really no different than applying filter criteria to a field constructed in query by an expression.
    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.

  8. #8
    gbleslie029 is offline Novice
    Windows XP Access 2003
    Join Date
    Jan 2016
    Posts
    2

    Sorted

    Quote Originally Posted by June7 View Post
    How would the calculated field depend on the filter criteria? It's really no different than applying filter criteria to a field constructed in query by an expression.
    Thank you guys for your help.


    Sorry if I didn't make myself clear but thank you all very much.


    I have used a suggestion from another site and it works perfectly.

    this is what I have used in the criteria part of my query in design view: [Start_Date]>=[Review_Date]+77


    Thanks guys and keep up the great work.


    G

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

Similar Threads

  1. Replies: 5
    Last Post: 01-04-2017, 02:13 AM
  2. Replies: 4
    Last Post: 08-30-2014, 10:23 AM
  3. Replies: 4
    Last Post: 12-17-2013, 08:31 AM
  4. Using VB to calculate a specific date
    By barryg80 in forum Programming
    Replies: 8
    Last Post: 12-05-2013, 09:05 AM
  5. Entering Criteria in a Query
    By wdrspens in forum Queries
    Replies: 4
    Last Post: 04-13-2011, 04:44 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