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

    simple snytax (lookup most recent record)

    this ought to be easy, but I'm missing "something" (probably right in front of my nose)

    I'm looking to return the contents of the field Version_ID in the most recent record base on the date in the field Version_Date of that record in the table tblVersionInf; and then assign it to a control property (which does work):



    vtxt = DLookup("[version_id]", "tblVersionInfo", DMin("[Version_date]", "tblVersionInfo"))
    me.lblVersionInfo.Caption = vtxt


    all it's returning is the first record.
    (if I change DMin to DMax... same result (so it has to be wrong!!))


    with many thanks in advance,
    mark

  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 don't have the field to be matched in the criteria of the DLookup().

    DLookup Usage Samples
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496
    so i changed the code to be:

    vtxt = DLookup("version_id", "tblVersionInfo", "version_date = #" & DMin("version_date", "tblVersionInfo") & "#")


    and the answer is always FALSE ?

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    What does the DMin() return on its own? And would a simple DMax() on the ID field get you the correct record?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496
    the table, tblVersionInfo, has (3) fields
    - Version_ID - long integer, increment
    - Version_date - date / time
    - Version_notes - long text

    what i'm trying to get is the entry of Version_ID for the most recent version_date, so what i presume i need to do is find what is the most recent date in the table (using the DMin() function, and then use that date as the criteria for the lookup. such as:

    criteria:
    "version_date = #" & DMin("version_date", "tblVersionInfo") & "#"

    -no?

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I understand what you're trying to do. If your version table is like mine, you increment the version with a new date, so for me DMax("VersionNumber", "VersionTable") gets me the most recent version. Your syntax looks fine, which is why I asked what the DMin() returned. Debugging from the inside out.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496
    it's similar to yours, with one exception that i missed including...

    the field: [ID], which is an auto-fill and the sequential number of the update's version
    of consequence, there may be be a more recent version in progress (to which i am adding notes of what is being included, etc. in a new record, with a new [ID]), but that i am not yet ready to issue. When i do issue the update is when I add the actual date of issue (version_date), and a brief text description (Version_ID) -which would be something like: "version 1.001 - rev: 2016.01.29" b(the 2 dates may actually not align -although they "usually" do...

    so the way to know which is the most recent issued version is to look for the most recent date (version_date)

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Then perhaps:

    DMax("VersionNumber", "VersionTable", "DateField Is Not Null")
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496
    BINGO! that worked

    thnx!

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Query Field Name Snytax Error
    By Vol71 in forum Queries
    Replies: 2
    Last Post: 07-20-2015, 01:28 PM
  2. lookup the most recent date for an entry
    By sdel_nevo in forum Forms
    Replies: 2
    Last Post: 06-03-2013, 01:30 AM
  3. Snytax Error - Counting a Not Null field
    By Huddle in forum Access
    Replies: 2
    Last Post: 06-29-2012, 12:30 PM
  4. Lookup Form (should be simple)
    By joshlee in forum Forms
    Replies: 3
    Last Post: 05-06-2009, 12:04 PM
  5. Simple record lookup?
    By Transeau in forum Access
    Replies: 0
    Last Post: 01-18-2006, 10:27 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