Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validate DLookup, DCount, DSum Data Returned

Status
Not open for further replies.

dpimental

Programmer
Jul 23, 2002
535
US
I am trying to find the most efficient way to validate the data returned from a DLookup, DCount or DSum. Although DLookup is easy, since it is an empty string..,

Is the best method simply the following ...
Code:
if DCount("[sales]","orders","[city] = 'Boston'") > 0 then
Msgbox "The Count of Orders for Boston is " & DCount("[sales]","orders","[city] = 'Boston'")
end if

if DSum("[sales]","orders","[city] = 'Boston'") > 0 then
MsgBox "The Total Sales for Boston is " & DSum("[sales]","orders","[city] = 'Boston'") 
end if

Is there a more efficient way to validate the DCount and DSum?

David Pimental
(US, Oh)
 
What do you mean by validate?

Speed wise, you making the calls twice unnecessarily.

Dim dblResult As Double

dblResult = DCount("[sales]","orders","[city] = 'Boston'")

if dblResult > 0 then
Msgbox "The Count of Orders for Boston is " & dblResult
end if

dblResult = DSum("[sales]","orders","[city] = 'Boston'")

if dblResult > 0 then
MsgBox "The Total Sales for Boston is " & dblResult
end if
 
Actually, I meant error handling.

For example if nothing is returned, then the variable assigned to DCount, DSum or DLookup would be null. That would produce an error such as invalid use of null.

David Pimental
(US, Oh)
 
dblResult = Nz(DCount("[sales]","orders","[city] = 'Boston'"),0)

is what you're after then.

Nz replaces null with the second parameter.
 
cool, thanks. That's just what I needed.

David Pimental
(US, Oh)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top