Solved

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

Posted on 2014-09-16
2
178 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
2 Comments
 
LVL 34

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 49

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

758 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now