#Error if no value

  • Thread starter Thread starter Dave Elliott
  • Start date Start date
D

Dave Elliott

The below code is my control source for an unbound textbox. if there is no
value or ocunt, then I get the error; #Error
How can I eliminate this ?

=DCount("[EmployeeID]","Employees","[Work Date] = " & Format([Work
Date],"\#mm/dd/yyyy\#"))
 
I would type:

=IIf (DCount("[EmployeeID]","Employees","[Work Date] = " & Format([Work
Date],"\#mm/dd/yyyy\#")) >0, DCount("[EmployeeID]","Employees","[Work Date]
= " & Format([Work Date],"\#mm/dd/yyyy\#")), Null)

Basically, if there is a date, show the date else show nothing... but
someone might have a better idea.
 
That requires 2 executions of the DCount. This may be better:

=Nz(DCount("[EmployeeID]","Employees","[Work Date] = " & Format([Work
Date],"\#mm/dd/yyyy\#")),Null)

Gina Whipp said:
I would type:

=IIf (DCount("[EmployeeID]","Employees","[Work Date] = " & Format([Work
Date],"\#mm/dd/yyyy\#")) >0, DCount("[EmployeeID]","Employees","[Work Date]
= " & Format([Work Date],"\#mm/dd/yyyy\#")), Null)

Basically, if there is a date, show the date else show nothing... but
someone might have a better idea.


Dave Elliott said:
The below code is my control source for an unbound textbox. if there is no
value or ocunt, then I get the error; #Error
How can I eliminate this ?

=DCount("[EmployeeID]","Employees","[Work Date] = " & Format([Work
Date],"\#mm/dd/yyyy\#"))
 
Both examples erred out ?
The end result is a count of course and the default count should be zero

Klatuu said:
That requires 2 executions of the DCount. This may be better:

=Nz(DCount("[EmployeeID]","Employees","[Work Date] = " & Format([Work
Date],"\#mm/dd/yyyy\#")),Null)

Gina Whipp said:
I would type:

=IIf (DCount("[EmployeeID]","Employees","[Work Date] = " & Format([Work
Date],"\#mm/dd/yyyy\#")) >0, DCount("[EmployeeID]","Employees","[Work
Date]
= " & Format([Work Date],"\#mm/dd/yyyy\#")), Null)

Basically, if there is a date, show the date else show nothing... but
someone might have a better idea.


Dave Elliott said:
The below code is my control source for an unbound textbox. if there is
no
value or ocunt, then I get the error; #Error
How can I eliminate this ?

=DCount("[EmployeeID]","Employees","[Work Date] = " & Format([Work
Date],"\#mm/dd/yyyy\#"))
 
=IIf([Work Date]="", "",[DCount("[EmployeeID]","Employees","[Work Date] = " &
Format([Work Date],"\#mm/dd/yyyy\#")))

Hopefully this works for you.
 
Back
Top