Results 1 to 8 of 8
  1. #1
    mikesal57 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2021
    Posts
    53

    Retrieving past data

    Hi Guys..



    Quick question :

    I have 2 tables , TODAY and HISTORY

    Is there a way that access can start with the first name in TODAY and pull up last 3 records in HISTORY ...then list its data in all 3

    Then continue with next name and repeat till it hits last name?

    I believe its something like "Advance Filter" in Excel

    Thxs

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,840
    Suggest show some example data to illustrate your description if you want more than a hint of the solution

    To get the last 3 you use the TOP predicate ordering by a date descending or similar and probably with a criteria to limit to a product type or similar.

    You may also need to consider using a cross tab query depending on the requirement

    Access is not excel and works in a completely different way and from your description I would have to query your design - if the two tables are effectively the same (i.e. tomorrow you transfer all the records from today into history) then there is no need to have two tables, one will do. You just control the view using queries and forms.

  3. #3
    mikesal57 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2021
    Posts
    53
    thxs CJ....

    I didn't forget you...just need to run out for a while...thxs

    I look up that cross tab query..its a start

  4. #4
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,367
    I suspect all of that should be in one table, not two. To archive a record, you'd have a date field. If the field is not null, it is archived (history).
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    Join Date
    Apr 2017
    Posts
    1,771
    Have your data in tables something like
    tblNames: NameID, ForeName, LastName
    tblYourData: YourDataID, NameID, SomeData1, SomeData2, ...,RecordDate

    Have a continous form filtered by NameID with recordsource as query like
    Code:
    SELECT TOP 3 n.ForeName, n.LastName, d.SomeData1, ..., d.RecordDate FROM tblYourData d INNER JOIN tblNames n ON n.NameID = d.NameID ORDER BY d.YourDate DESC
    User selects name in unbound combo on form, and afterupdate event of combo sets the filter property of form to NameID of selected name, and sets the form filter ON. The form displays last 3 entries for this name with last entry (i.e. current one) at top.

    Any record in table, which doesn't have topmost RecordDate for given NameID, is archive record.

    With such design, you also can design an UDF, which returns the active date for any given NameID at any given date. Consider possibilities using something like this!

  6. #6
    madpiet is offline Expert
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    550
    Quote Originally Posted by mikesal57 View Post
    Hi Guys..

    Quick question :

    I have 2 tables , TODAY and HISTORY

    Is there a way that access can start with the first name in TODAY and pull up last 3 records in HISTORY ...then list its data in all 3

    Then continue with next name and repeat till it hits last name?

    I believe its something like "Advance Filter" in Excel

    Thxs
    Some thing like this... failing that, look up Allen Browne's TOP N per Group on his website www.allenbrowne.com.au (I think - he's a former Access MVP)

    SELECT t.PersonID, t.FName, t.LName, h.*
    FROM tblToday as t
    LEFT JOIN (SELECT TOP 3 * FROM History h
    ORDER BY SomeDate DESC) ht
    ON t.PersonID = ht.PersonID
    ORDER BY t.FName, t.LName;

  7. #7
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,119
    Allen Browne's website is http://www.allenbrowne.com.
    The Top N per group example is at http://www.allenbrowne.com/subquery-01.html#TopN

    As others have already said it may be easier if the data is in one table not two
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  8. #8
    madpiet is offline Expert
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    550
    Quote Originally Posted by madpiet View Post
    Some thing like this... failing that, look up Allen Browne's TOP N per Group on his website www.allenbrowne.com.au (I think - he's a former Access MVP)

    SELECT t.PersonID, t.FName, t.LName, h.*
    FROM tblToday as t
    LEFT JOIN (SELECT TOP 3 * FROM History h
    ORDER BY SomeDate DESC) ht
    ON t.PersonID = ht.PersonID
    ORDER BY t.FName, t.LName;
    While you could do something like

    SELECT col1, col2, col3
    FROM tblToday
    UNION ALL
    SELECT col1, col2, col3
    FROM tblHistory

    I think you lose the benefit of indexing when you do that. (I could be wrong, though). Stay away from plain UNION because it does a SORT and a DISTINCT under the covers.

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

Similar Threads

  1. Replies: 1
    Last Post: 12-26-2020, 03:21 PM
  2. Retrieving external Data
    By DMT Dave in forum Access
    Replies: 3
    Last Post: 04-14-2020, 09:56 AM
  3. Retrieving data from linked database
    By dwilkerson43 in forum Access
    Replies: 6
    Last Post: 10-24-2018, 09:39 AM
  4. Web retrieving of Data
    By drunkenneo in forum Programming
    Replies: 1
    Last Post: 05-23-2014, 01:38 AM
  5. Retrieving data on my website
    By kattys in forum Access
    Replies: 1
    Last Post: 04-27-2010, 05:02 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