How to find a null or blank entry?

  • Thread starter Thread starter David Portwood
  • Start date Start date
D

David Portwood

In a table or form, how can I find the first cell in the field with null or
"" contents?
 
Keep in mind that blank "" and null are not the same thing. How about
using "Is null" as the condition?
 
Keep in mind that blank "" and null are not the same thing. How about
using "Is null" as the condition?

I'm looking for two answers: finding nulls and finding empty strings.

I have used "is null" in the Find dialog and it didn't seem to work. Now it
occurs to me that maybe the cells contain empty strings, not nulls. So how
would I find an empty string? Put "" as the condition?
 
Tables are sets, so have no intrinsic order. The concept of 'first' row (not
cell, that's a spreadsheet concept, not a database one) is meaningless in a
table, therefore. You can impose an order by means of query, however, so
lets assume you want to find the first row(s) in MyTable with a Null or
zero-length string in column MyText when a table is ordered by column MyDate.

You can use the TOP option, sorting the rows in date order:

SELECT TOP 1 *
FROM MyTable
WHERE LEN(MyText & "") = 0
ORDER BY MyDate;

Or you can identify the row in question in subquery and return that row in
the outer query like so:

SELECT *
FROM MyTable
WHERE LEN(MyText & "") = 0
AND MyDate =
(SELECT MIN(MyDate)
FROM MyTable
WHERE LEN(MyText & "") = 0);

In form based on the table you could call a function in the form's module:

Private Function FindEmptyMyText()

Dim rst As Object

Set rst = Me.Recordset.Clone

With rst
.FindFirst "Nz(MyText,"""") = """""
If Not .NoMatch Then
Me.Bookmark = .Bookmark
End If
End With

End Function

This would find the first matching row in the form's current sort order.
the function could be called from a button for instance by entering as its On
Click event property:

=FindEmptyMyText()

Ken Sheridan
Stafford, England
 
Take a look at Ken's response. His is far more complete than I would
have offered. He did a nice job.
 
Thank you, Joseph.

Ken

Joseph Meehan said:
Take a look at Ken's response. His is far more complete than I would
have offered. He did a nice job.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top