473,857 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Find last entry which isn't null


I have used the DLast("[tblName]![ColumnName]","[criteria]")function
to find and display the last entry in a table. How would I go about
displaying the last record in a table that is not Null?

Thanks in advance

Nov 12 '05 #1
2 8831
First and Last are not very useful.

Presumably you have some kind of field that you can use to determine the
last entry, e.g. an AutoNumber or a Date/Time of entry? Assuming that you
want to find the Surname from tblClient, where ClientID determines which was
the last entry:

1. Paste the function below into a module, and save.

2. Try:
=ELookup("Surna me", "tblClient" , "Surname Is Not Null", "ClientID DESC")
Function ELookup(Expr As String, Domain As String, _
Optional Criteria, Optional OrderClause)
On Error GoTo Err_ELookup
'Purpose: Faster and more flexible replacement for DLookup()
'Arguments: Same as DLookup, with additional Order By option.
'Author: Allen Browne. al***@allenbrow ne.com
'1. To find the last value, include DESC in the OrderClause, e.g.:
' ELookup("[Surname] & [FirstName]", "tblClient" , , "ClientID DESC")
'2. To find the lowest non-null value of a field, use the Criteria,
' ELookup("Client ID", "tblClient" , "Surname Is Not Null" , "Surname")
'Note: Requires a reference to the DAO library.
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSql As String

'Build the SQL string.
strSql = "SELECT TOP 1 " & Expr & " FROM " & Domain
If Not IsMissing(Crite ria) Then
strSql = strSql & " WHERE " & Criteria
End If
If Not IsMissing(Order Clause) Then
strSql = strSql & " ORDER BY " & OrderClause
End If
strSql = strSql & ";"

'Lookup the value.
Set db = DBEngine(0)(0)
Set rs = db.OpenRecordse t(strSql, dbOpenForwardOn ly)
If rs.RecordCount = 0 Then
ELookup = Null
ELookup = rs(0)
End If

Set rs = Nothing
Set db = Nothing
Exit Function

MsgBox Err.Description , vbExclamation, "ELookup Error " & Err.Number
Resume Exit_ELookup
End Function
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html

"PC" <cu*****@eircom .net> wrote in message
news:8c******** *************** **@posting.goog le.com...

I have used the DLast("[tblName]![ColumnName]","[criteria]")function
to find and display the last entry in a table. How would I go about
displaying the last record in a table that is not Null?

Thanks in advance


Nov 12 '05 #2
cu*****@eircom. net (PC) wrote in news:8c******** *************** **@posting.goog le.com:

I have used the DLast("[tblName]![ColumnName]","[criteria]")function
to find and display the last entry in a table. How would I go about
displaying the last record in a table that is not Null?

Thanks in advance


strLastValue = DLast("myTable. myColumn","myTa ble","myColumn is not null")

Ross Presser -- rpresser AT imtek DOT com
.... seeking a new quote ...
Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: gsb | last post by:
I'm not very good in mySQL but am trying to modify a script. It has to do with a log table. I want to retrieve the last 2 log records (if any) and if the last log entries are the same as my current (to be) entry, simply update the time in the last entry. But if not, simply insert the new entry. My question is how to select the last two entries from the log table? CREATE TABLE broadcast_log ( id mediumint(8) unsigned NOT NULL...
by: zaceti | last post by:
I'm new to MySQL and I am having a problem selecting the highest valued date/time for a particular day. Here is the table structure: +--------------+-----------------+-----+----+--------+--------------+ | Field | Type | Null| Key| Default|Extra | +--------------+-----------------+-----+----+--------+--------------+ | id | int(10) unsigned| | PRI| NULL |auto_increment| | timestamp | datetime ...
by: Vani Murarka | last post by:
Hi Everyone, Does .NET offer any collection class which will give me objects last *accessed* such that I may build a least-recently-used cache that kills off objects that haven't been used for awhile? Or is there any other way to implement this kind of a cache / collection where one can do this kind of cleanup based on least-recently-used objects?
by: Filips Benoit | last post by:
Hi, TBL_CONTACT_PERSON CNTP_ID (auto) CNTP_LAST_NAME (required = yes) CNTP_FUNCTION (required = no) CNTP_..... (all required = no) FRM_CONTACT_PERSON_ADD_NEW Property DATA ENTRY = YES
by: Sue | last post by:
I'm working on a database that keeps track of employees hired by a general contractor on a project by project basis. These employees are hired to work on a project and are then laid off either at the end of the work they were hired to do or at the end of the project. Any employee may be hired, laid off and rehired several times during the course of time. The tables I have and the critical fields to my question are: TblEmployee EmployeeID...
by: Sean Berry | last post by:
I need to find the second to last occurence of a "." in a string. Basically I am taking a URL like http://this.is.mydomin.com/path/to/file.txt and want to extract /path/to/file.txt I thought I would be able to do it like this: ----------------------------------------------------
by: magix | last post by:
Hi, when I read entries in file i.e text file, how can I determine the first line and the last line ? I know the first line of entry can be filtered using counter, but how about the last line of entry in EOF while loop ? while (! file.eof() ) { ....
by: Alami | last post by:
I'm newdie in c programming. this is my first project in programming. I have to write a program for a airline reservation. this is what i have done yet. but when it runs it shows the number of seats as 0 and the flight no. is also repeating. If any can tell why is this please help me. #include<stdio.h> #include<ctype.h> #include<conio.h> #include<memory.h>
by: karinmorena | last post by:
I'm having 4 errors, I'm very new at this and I would appreciate your input. The error I get is: Week5MortgageGUI.java:151:cannot find symbol symbol: method allInterest(double,double,double) Location: class Week5MortgageGUI Week5MortgageLogic allint = logic.allInterest(amount, term, rate); Week5MortgageGUI.java:152:cannot find symbol symbol: method allInterest(double,double,double) Location: class Week5MortgageGUI
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.