Results 1 to 9 of 9
  1. #1
    MattyL is offline Novice
    Windows Vista Access 2007
    Join Date
    Nov 2011
    Posts
    4

    Access form calculation

    Hi



    I've been reasonably clever and, on a form, created a text box that calculates the result of subtracting data (a date) in one text box from another date in a second text box (using DateDiff).

    The correct answer is showing in the form.

    However, I want to run a query or a report that is based on this automatically generated number, but whenever I view a table, query or report the 'answer' does not appear in the field. Therefore I can't run a query based on this value.

    Any advice?

  2. #2
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Can you explain with a little more detail exactly what you need to do once you have your 'answer' on the Form?

  3. #3
    MattyL is offline Novice
    Windows Vista Access 2007
    Join Date
    Nov 2011
    Posts
    4
    Hi

    Thanks for responding so quickly.

    The form contains the following fields...

    1. Date work order placed (e.g. 1st November 2011)
    2. No. of days elapsed since order placed (this is worked out using DateDiff, i.e. subtracting today's date from date order placed, to give a value), using the e.g. of 1st November 2011 the value returned would be 7, based on today being 8th November 2011)

    I want to run a query or a report which allows me to view, say, all orders placed more than 7 days ago. I can do this on a query by inputting a criteria of < (a specific date) in the 'date of order' field, but this is not ideal. I'd rather put a value in the 'no. of days elapsed' field, e.g. to show all works orders which are over 7 days old (>7), and then see this info on a report.

    Am I making myself clear enough?

    Thanks

  4. #4
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Try this in the Criteria for the date field in your query.

    DateDiff("d",[DateField],Date())>7

  5. #5
    MattyL is offline Novice
    Windows Vista Access 2007
    Join Date
    Nov 2011
    Posts
    4
    Yep, that appears to work. Thank you very much for your help.

    Shame though that Access doesn't allow for the calculation to be done within the table.

    All the best

  6. #6
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    You CAN do calculations in your Access Tables - using the same logic.
    Create a field and put the calculation into the field.

    BUT, it is better to do calculations like the one you need in a Query.
    The value in the calculated field [if you decide to have one] will change every day - so it is not a REAL value.
    Since it can be calculated at any time using the query, it is better not to store it in the table.
    The query will make the value available to you whenever you need - and this is just a more efficient way of doing things.

    All the best!!

  7. #7
    MattyL is offline Novice
    Windows Vista Access 2007
    Join Date
    Nov 2011
    Posts
    4

    Thumbs up

    Thanks for your help - I got it working.

    However, I've now moved the goalposts a little.

    My new form has three input fields, and one automatically generated field which has used the datediff expression:

    1. Machine name
    2. Date fault reported
    3. Date fixed
    4. Days out of service (field 3 minus field 2)

    What I now want to do is run a report or query in which I select a particular machine to see how many times, and for how many days, it has been out of service. I know I could do this really easily from Excel using a pivot table, but my database is doing other stuff too and I would like to keep using it.

    So the report would look something like this...

    Machine No. Date fault reported Date fixed Days out of service
    1 10/10/11 12/10/11 2
    1 15/10/11 18/10/11 3

    Total days out of service 5

    Can you help?

  8. #8
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    If you want to just search for information on ONE Machine at a time, you can create what is known as a parameter query and what that will do is prompt you for a machine # each time you run the query.

    I just created a real simple query with 3 fields [including a field with a name in it.
    In the criteria of the Name field, I put this:
    [Name?]

    When I ran the Query, it prompted me for a Name for that field and when I provided the Name, the query only returned the row that had a matching value in that field.

    You could put something like [Machine# ?] in the Criteria for Machine Number in your query.

    I hope this helps!

  9. #9
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    P.S. You will have to add the 'Days_Out' field and do the DateDiff calculation in there.

    It should look like something like this in the Query field that you create:
    Code:
     Days Out Of Service: DateDiff("d", [DateFaultReported],[DateFixed])

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

Similar Threads

  1. Calculation in a form Access 2003
    By 1943 in forum Forms
    Replies: 2
    Last Post: 02-16-2011, 12:28 PM
  2. Query calculation from a form???
    By daisy19 in forum Queries
    Replies: 1
    Last Post: 07-08-2010, 10:10 AM
  3. Calculation in access forms
    By miziri in forum Programming
    Replies: 13
    Last Post: 11-23-2009, 05:55 AM
  4. Calculation field in form
    By ste_pie87 in forum Access
    Replies: 1
    Last Post: 03-24-2009, 08:28 PM
  5. Subform vs main form calculation
    By fadone in forum Forms
    Replies: 17
    Last Post: 12-21-2005, 07:27 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