Results 1 to 2 of 2
  1. #1
    Twi78 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2015
    Posts
    1

    Return the last known value

    Hi all.



    I hopefully have a simple query to solve for the more seasoned user. I have a table as follows:

    Event¦Value
    1¦5499
    2¦2433


    5¦2300


    Where there are spaces in the table, I would like to do populate it with the last known value. The 'Event' field will always be in numerical order and so the output would look like:

    Event¦Value
    1¦5499
    2¦2433
    2433
    2433
    5¦2300
    2300

    Can anyone suggest how I could write a query to achieve this?

    Thanks
    G

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I had hoped the answer would be in http://allenbrowne.com/subquery-01.html#AnotherRecord

    But I am not having success. The example data lacks a group identifier so the example query won't work. If this can be done by query alone, it is far more advanced and complicated than I have ever attempted. I would use VBA to open and manipulate recordset object. Like:
    Code:
    Sub FixIt()
    Dim rs As DAO.Recordset
    Dim lngData As Long
    Set rs = CurrentDb.OpenRecordset("SELECT * FROM Table1 ORDER BY Event;")
    If Not rs.EOF Then lngData = rs!Data
    While Not rs.EOF
        If IsNull(rs!Data) Then
            rs.Edit
            rs!Data = lngData
            rs.Update
        Else
            lngData = rs!Data
        End If
        rs.MoveNext
    Wend
    End Sub
    Procedure assumes record 1 has data. Note that I changed field name from Value to Data.

    Value is a reserved word. Should not use reserved words as names.
    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. return value
    By sharonir22 in forum Queries
    Replies: 1
    Last Post: 05-20-2015, 06:00 AM
  2. Replies: 9
    Last Post: 08-19-2014, 12:41 PM
  3. Replies: 2
    Last Post: 06-03-2013, 11:02 AM
  4. Specify return value
    By Desstro in forum Queries
    Replies: 2
    Last Post: 06-19-2010, 02:12 AM
  5. Return value of row above
    By marimar1097 in forum Access
    Replies: 7
    Last Post: 10-20-2009, 08:06 AM

Tags for this Thread

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