Solved

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

Posted on 2014-09-16
2
179 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

867 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

21 Experts available now in Live!

Get 1:1 Help Now