Solved

Trying to get the next to the last record field in query designer

Posted on 2014-09-16
2
190 Views
Last Modified: 2014-09-17
I'm using DLast to attempt to get a field into a query with :

Previous Running Note: DLast("[RunningNote]","tblMemberRunningNotes","[MemberID] = [MemberID]")-1

But that isn't working.  What I want is not the last RunningNote but rather the next to the last one.

--Steve
0
Comment
Question by:SteveL13
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 38

Assisted Solution

by:PatHartman
PatHartman earned 250 total points
ID: 40326584
Last is a nebulous concept since it relies on Order and even if you include an Order By clause in your query, you may not get what you think is the Last record.  The DLast() function will not reliably return the record you think you want.

One possibility is to create a query that orders the records descending by the field(s) you think will get you the "Last" record on top and select the Top 2 records.  Then sort that query ascending and select the Top 1 record.
0
 
LVL 51

Accepted Solution

by:
Gustav Brock earned 250 total points
ID: 40327396
I would use a recordset:

lngMemberID = <the member id to look up>
strSQL = "Select Top 2 [RunningNote] " & _
    "From tblMemberRunningNotes " & _
    "Where [MemberID] = " & lngMemberID & " " & _
    "Order By [YourNoteDateField] Desc"

Set rst = dbs.OpenRecordset(strSQL)
If rst.RecordCount >= 2 Then
    rst.MoveNext
    strNote = rst!RunningNote
End If

/gustav
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question