Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-09-16
2
Medium Priority
?
210 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 40

Assisted Solution

by:PatHartman
PatHartman earned 1000 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 52

Accepted Solution

by:
Gustav Brock earned 1000 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

885 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