Results 1 to 5 of 5
  1. #1
    NAT is offline Novice
    Windows 10 Access 2013
    Join Date
    Nov 2015
    Posts
    3

    Select next SampleID by Test Age - DMax?


    Hi,

    I have created an access system which allows me to input, test and report test samples and cannot for the life of me figure out how to code a part which is crucial.

    I enter the samples on my main test entry form. There is a sub form on the page which I enter the samples onto which usually contains between 1 and 6 samples. The main form is the group table and the sub form is the sample table so I have for example a group ID of 108 and say 3 samples within this group with their own sample ID's. Each sample has a test age assigned to it for example:

    GROUP ID: 108 - Below samples are in group 108
    SAMPLE ID 100 - Test Age = 7 days (When tested I enter the strength against the sample)
    SAMPLE ID 101 - Test Age = 14 days (When tested I enter the strength against the sample)
    SAMPLE ID 102 - Test Age = 28 days (When tested I enter the strength against the sample)

    I would like to be able to tell the sample at 28 days to look at the sample from 14 days or whatever test age is next down and see the strength so I can do some math to work our growth since the last test. I can enter sample test dates from 1 to 100 so would always need it to look at the previous test and test age...?

    They are in a group so I figure I could say check SampleID x in GroupID where TestAge = < current SampleID or along them lines? Am I totally off key here? Would a loop be required? I'm kinda lost at this point...

    If I need to provide ANY details for someone to help me no problem.

    Click image for larger version. 

Name:	Tables.PNG 
Views:	14 
Size:	59.5 KB 
ID:	22863Click image for larger version. 

Name:	Table-Query.jpg 
Views:	14 
Size:	94.2 KB 
ID:	22865Click image for larger version. 

Name:	resultscreen.PNG 
Views:	14 
Size:	77.5 KB 
ID:	22866

    I can get the max by using DMax: DMax("SampleTestAge","TblSample","[GroupID]=" & [GroupID]) but not sure how to tell it to look at the result prior so I can work out the growth rate.

    Any help would be very much appreciated

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    When I encounter hurdles like these, I turn to the query designer. I will start to build queries that provide me with the desired results. The most difficult part is to distinguish a small section of the problem and resolve small sections, one at a time. The big picture will always cloud things for us.

    Try to set aside the working example you have. Imagine the only problem is querying the data relative to 14 days. You should already have the means to do this in the working example you set aside. Extract that '14 days' part and that part only. Using Notepad and a text file, make notes. Note the value 14. Make notes of valid key values, like a valid GroupID and SampleID.

    Start building some SQL that retrieves a valid Group and sample that is relative to 14. Use the Query Designer to create a new Query Object and hard card criteria for the GroupID and the SampleID, as well as the magic value, 14. When I use the query designer as a scratch pad, I will sometimes need to save the query. When I do this, I use a special naming convention to avoid confusing these 'scratch pad objects' with production objects. I use the prefix A_A_.

    After hardcoding some criteria, you should have something similar to your working example that you set aside earlier. The main difference being it retrieves an isolated entity or Tuple. Now, you can expand upon this by including another Tuple, or group of fields. Use a similar process to isolate 7 or maybe hardcode 28. Choose one of the two, maybe 7, and see if you can get some working queries. Maybe you will need to use a subquery. It is OK to build more than one query object and compare the SQL. Determine the best way to merge or JOIN them.

    After you are able to retrieve the desired subsets, revisit the working example you set aside earlier. Now you will need to find something else. You will need to determine an Event. What you will be doing is moving from the data side to the application side. With your SQL in hand, determine which Event will command retrieval of the data.

  3. #3
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    I might have a suggestion for a subquery but don't understand your date relationships. I don't get why there are sample date/time fields in tblGroup as well as tblSample. If they are directly related, then I believe the design is wrong. I'm thinking there should be one fixed create date for a sample grouping and sample dates for the samples. The sample dates should come from tblSample only, by way of group id. It might be possible to get the Max date of a sample that is less than the one before it within a group regardless.

  4. #4
    InsuranceGuy is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Aug 2015
    Location
    Colorado
    Posts
    126
    Assuming Strength is stored in "TestedStrength", try this as a field definition:

    Code:
    IIF([SampleTestAge]>7,dlookup("TestedStrength",""TblSample","[GroupID]=" & [GroupID] & " AND [SampleTestAge]=" & [SampleTestAge]/2),null)
    This takes advantage of the numeric pattern of 7, 14, 28 being multiples of 2. The previous sample, if it exists, will be the current sample test age divided by 2 with the same groupID. Within that record, you want the TestedStrength field.

    Always interested in the concrete business. My father in law is a concrete cutter in California. If I can be of further assistance, please let me know.

    Cheers,


    Jeff
    Last edited by InsuranceGuy; 11-30-2015 at 04:27 PM. Reason: I missed a paren... corrected

  5. #5
    InsuranceGuy is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Aug 2015
    Location
    Colorado
    Posts
    126
    I missed a paren and updated the code above.

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

Similar Threads

  1. DMAx Question for Report - DMax <= Dtae
    By crimedog in forum Access
    Replies: 8
    Last Post: 12-29-2014, 09:31 PM
  2. Replies: 25
    Last Post: 11-23-2014, 02:43 PM
  3. Test String test besed on table data
    By igourine in forum Programming
    Replies: 3
    Last Post: 12-01-2013, 06:16 AM
  4. Replies: 6
    Last Post: 07-24-2012, 03:02 PM
  5. Keying in Test answers to Access DB from Written Test
    By CityOfKalamazoo in forum Access
    Replies: 3
    Last Post: 03-01-2010, 08:58 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