Dmin for nulls?

RogerH

Registered User.
Local time
Today, 18:17
Joined
Mar 21, 2016
Messages
34
I have a table of Transactions "tblTransactions" in which more than one row will have the same PO number. Each row has a date field called "POSubDate" I need to know if *any* row has a null in that field.

I tried:

If IsNull(DMin("POSubDate", "tblTransactions", "POno = " & Chr(34) & Me.PONo & Chr(34))) Then ...

But: DMin() returns Null if they are ALL null. But if ANY have a date, it returns the earliest date.

I need a DNull() function!
 
My first thought:

If DCount("*", "tblTransactions", "POno = " & Chr(34) & Me.PONo & Chr(34) & " AND POSubDate Is Null) > 0 Then
 
Write a query similar to this:

Code:
Select A, B, etc., IsNull(X) As XNull From ....

Then do a DCount("[XNull]", "myquery", "[XNull]=True" )
 
Doc, you're saying my DCount() won't work? I didn't test, but I don't see why it wouldn't work.
 
Giving the OP a second viewpoint, not meant to downplay your solution. However, I recall from some years a go a discussion with someone about how DCount and a few of the other Domain Aggregate functions have a hard time with nulls. No, I just saw this post and haven't had time to try it. I wasn't saying it would or wouldn't work. Just offering another viewpoint. You should know by now that I do that because it always helps the newcomers to see other ways to skin cats....
 
Either your extra query or the DCount would require a criteria on POno.
 
Thanks guys,
OK a query with an Nz([POSUbDate])
and then count the zeros.

Although, now I'm thinking I *could* write a DNull() function that works via ADO, it would probably be slower..
 
Code:
If DCount("*", "tblTransactions", "POno = " & Chr(34) & Me.PONo & Chr(34) & " AND POSubDate IS NULL") > 0 Then
    ' At least one row has a null value in "POSubDate"
    ' Your code here...
Else
    ' No row has a null value in "POSubDate"
    ' Your code here...
End If

Is this code using DCount() usable?
 
If you only want to check if there is at least one record with zero, DLookup would also suffice.

Auxiliary function:
Code:
Public Function DExists(ByVal Domain As String, _
               Optional ByVal Criteria As String = vbNullString) As Boolean

   DExists = Nz(DLookup("True", Domain, Criteria), False)

End Function

Usage:
Code:
Dim CriteriaString as String
CriteriaString = "POno = '" Me.PONo & "' AND POSubDate Is Null"
if DExists("tblTransactions", CriteriaString) then
...

See also:
 
Last edited:

Users who are viewing this thread

Back
Top Bottom