Results 1 to 5 of 5
  1. #1
    BigMac4 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Aug 2012
    Posts
    30

    Query based on dates ish

    First off thanks to Rod on my last impossible question how he sorted it i will never understand but he did.

    Well he goes with problem number 2 not sure how i can explain it, i have added a couple of images for you to look at that might help with what i am after.
    Click image for larger version. 

Name:	Sample1.jpg 
Views:	10 
Size:	79.5 KB 
ID:	8949Click image for larger version. 

Name:	Sample2.jpg 
Views:	9 
Size:	83.4 KB 
ID:	8950
    I have a table (sampletaken) in this table i have
    Unique ID


    Code
    Date
    A
    B
    C
    D
    E

    I have a second Table (Codechange) in this table i have
    Unique ID
    Code
    Date
    A
    B
    C
    D
    E

    Right what we have is people taking samples and inputing data into Sampletaken just Date and Code, The ABCDE are ingredient totals for each Code.

    We also have someone coming along every so often and changing the ingredients in Codechange they will input all fields Date,Code,ABCDE.

    What i need is a form so that if someone wanted to take a sample they would enter in the code of the sample and the date and it would automatically return the current ingredient list, for example the last change in the list but before the date the sample was taken.

    I have made a database where it auto returns the ingredient lists but the problem is if i was to change the ingredients on monday then sample on wednesday all the previous samples of that code would be the same ingredients. This has really got me stumped and i dont know enough about SQL/Queries to design what apears to be a massive undertaking. Now that being said im sure if i have explained this well enough (probably not) there will be someone whom will come up with the answer in about ten mins.

    Cheers in advance

    Mac

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You can open a recordset on the codes table using an SQL statement that finds the most recent record for the given code (or the most recent previous to the date in the samples table if appropriate). Then copy values from the recordset to the form.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Don't save the code value in SampleTaken, save the ID value. Change the Code field in SampleTaken to number type, store the CodeChange ID value in that field.

    The tables will be related by the ID/Code primary and foreign key fields of the two tables. Whenever you want to see the ABCDE values associated with the SampleTaken record, build a query that joins the two tables on the ID/Code fields. No need for the ABCDE fields in SampleTaken.

    If you don't use table relationship then will have to keep the ABCDE fields in SampleTaken and use VBA code to save the values to record. This does not take advantage of relational database concept.

    Restricting the combobox RowSource to only the most recent record prior to sample date for each code will require subquery. Review http://allenbrowne.com/subquery-01.html
    Look at the example for: Top n records per group.

    I recommend more descriptive names for the date fields, such as SampleDate and CodeDate.
    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
    BigMac4 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Aug 2012
    Posts
    30
    Any chance of an example database being made then I can look at how it works and convert it into my database please

    Cheers Mac

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Not much chance. Here is a reference on database design http://forums.aspfree.com/microsoft-...es-208217.html

    There are many examples. Open Access and an assortment is presented.

    Attempt a design and post it for analysis.
    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. Newest dates based on criteria
    By benjammin in forum Queries
    Replies: 13
    Last Post: 05-15-2012, 02:49 PM
  2. Filtering based on form dates
    By cbh35711 in forum Programming
    Replies: 3
    Last Post: 03-13-2012, 11:46 AM
  3. Query input dates for range of dates in two fields
    By kagoodwin13 in forum Queries
    Replies: 3
    Last Post: 02-13-2012, 04:25 PM
  4. Importing data based on dates
    By sentil in forum Programming
    Replies: 1
    Last Post: 07-09-2011, 01:56 AM
  5. Replies: 6
    Last Post: 12-10-2009, 08:12 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