Results 1 to 5 of 5
  1. #1
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496

    most recent entry

    i really have looked for a resolution on the web (and have found several, often contradictory, and (so it seems to me) far too complex approaches)



    my quandary sees to be defining a criteria for the most recent date (see code for a walk through of the difficulty)

    as always, with much appreciation in advance,
    m.

    Code:
        
        're-create the table with the current status for all fixture tags
        'if the tag has been submitted, create a record for it's most recent entry in tbl____
        'else create a record in tbl___   (tags not yet submitted)
        
        
        ' loop through all of the Tags in the project that are not VOID
        Set gsDbs = CurrentDb
        Set gsRst = _
            gsDbs.OpenRecordset("SELECT [Tag], [Void] " & _
            "FROM tbeFixtureTagDetails WHERE NOT VOID", _
            dbOpenDynaset)
        
        With gsRst
            DoCmd.GoToRecord , "", acLast
            DoCmd.GoToRecord , "", acFirst
            Do Until .EOF
        
                'check if there is a submittal for the fixture type ([Type])
                blnSubmitted = (DCount("[Tag]", "tbeSubmittalDetails", "[Tag] = '" & !Tag & "'") > 0)
                
                'if there is, then look up the status for the most rescent entry for each [Tag]
                'qrySubmittalDetails contains information about each submittal (Submtl_ID, DateRtrnd...)
                'and of all of the "detail" related to it ([Tag], [Action]...)
                
                If blnSubmitted Then
            
        ' *** IT IS THIS NEXT LINE THAT I AM STUCK ON:
            
                    gsCriteria = "[Tag] = '" & !Tag & "' AND [DateRtrnd] = Max("[DateRtrnd]", "qrySubmittalDetails") "
                        
                    strID = DLookup("[SubmittalID]", "qrySubmittalDetails", gsCriteria)
                    strStatus = Nz(DLookup("[action]", "tbeSubmittalDetails", vCriteria), "unknown")
                               
                    '.... add the tag, its current status, the ID of its most recent submittal, and the submittal date...
                    
                Else
                
                End If
            Loop
        End With

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Maybe:

    gsCriteria = "[Tag] = '" & !Tag & "' AND [DateRtrnd] = #" & DMax("[DateRtrnd]", "qrySubmittalDetails") & "#"
    Last edited by June7; 03-14-2022 at 11:48 AM.
    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.

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Also whilst this does not affect this particular issue
    Code:
            DoCmd.GoToRecord , "", acLast
            DoCmd.GoToRecord , "", acFirst
    It is not doing what I think you want it to do? You are moving record position of form records there.
    For the recordset you would use
    Code:
    .MoveLast
    .MoveFirst
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    You need to use dMax not Max:
    Code:
     gsCriteria = "[Tag] = '" & Me.Tag & "' AND [DateRtrnd] = #" & dMax("[DateRtrnd]", "qrySubmittalDetails","[Tag]='" & Me.Tag & "'")  & "#" 
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  5. #5
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    NOTE: "Tag" and "Type" are reserved words and shouldn't be used for object names....

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

Similar Threads

  1. Most Recent Date an Entry Was Made
    By elhale in forum Queries
    Replies: 3
    Last Post: 09-28-2016, 02:48 PM
  2. Selecting most recent entry in a table
    By mjwillyone in forum Programming
    Replies: 4
    Last Post: 01-04-2016, 09:54 AM
  3. lookup the most recent date for an entry
    By sdel_nevo in forum Forms
    Replies: 2
    Last Post: 06-03-2013, 01:30 AM
  4. Help getting the most recent value
    By murry in forum Queries
    Replies: 2
    Last Post: 03-14-2013, 02:41 PM
  5. Return most recent entry for each item
    By GenAp in forum Queries
    Replies: 1
    Last Post: 02-04-2010, 05:30 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