Results 1 to 3 of 3
  1. #1
    Cafe2UEMP is offline Novice
    Windows 10 Access 2007
    Join Date
    Nov 2017
    Posts
    8

    Dlookup and latest date

    Hi

    I have a table which contains product prices. These vary (increase/decrease) based on a date which becomes a new record in the table.


    I want to find a price based on the price in the table based on the date entered in a form.

    I am trying to use a dlookup function with a date criteria but am a bit lost on this.

    Would appreciate a bit of help.

    Thanks

    David

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,644
    Nevermind, not reliable code.

    Really should save the record ID from Products table into the order record.
    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
    Apr 2017
    Posts
    1,776
    Here is an UDF I use to get such values:

    Code:
    Public Function ValidValue(parTable As String, IdField As String, IdCond As String, IdIsString As Boolean, RetField As String, DateField As String, parDate As Date)
        Dim dbs As Database
        Dim rs As Recordset
        Dim varQstr As String
        ' The function returns the value of RetField from table parTable
        ' where IdField equals IdCond and DateField is nearest past or equal to parDate.
        ' The parameter IdIsString must be True, when IdField has Text format
        
        On Error GoTo Err_ValidValue
        Set dbs = CurrentDb
        varQstr = "SELECT [" & RetField & "] FROM " & parTable & _
                " WHERE [" & DateField & "] <= " & Format(parDate, "\#mm\/dd\/yyyy\#") & _
                " And [" & IdField & "] = " & IIf(IdIsString, "'" & IdCond & "'", IdCond) & _
                " ORDER BY [" & DateField & "] DESC"
        Set rs = dbs.OpenRecordset(varQstr)
        rs.AbsolutePosition = 0
        ValidValue = rs.Fields(0).Value
        
    Err_ValidValue:
            rs.Close
            dbs.Close
            Set rs = Nothing
            Set dbs = Nothing
    End Function

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

Similar Threads

  1. Filter latest date of a value
    By ratercero in forum Queries
    Replies: 7
    Last Post: 05-31-2017, 01:27 PM
  2. latest date
    By slimjen in forum Programming
    Replies: 11
    Last Post: 09-12-2014, 08:46 PM
  3. Value of latest date
    By v!ctor in forum Queries
    Replies: 3
    Last Post: 02-27-2013, 03:48 PM
  4. How do you get the latest date?
    By radicrains in forum Queries
    Replies: 6
    Last Post: 10-27-2010, 08:59 PM
  5. Latest Date Records
    By Rick West in forum Queries
    Replies: 1
    Last Post: 09-25-2009, 11:16 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