Checking Form/Query for Record (1 Viewer)

Wicklund

Registered User.
Local time
Today, 03:39
Joined
Jun 7, 2002
Messages
56
I am opening a form based on given criteria (the form is based on a query). There will be either one record for the given criteria, or no record. When there is no record, I get an error "You entered an expression that has no value."

Can I check to see if the form/query will be empty before opening it?

Thank you,

Steve
 

Fizzio

Chief Torturer
Local time
Today, 03:39
Joined
Feb 21, 2002
Messages
1,885
use the dcount method ie

If dcount("[ID]", "qryQueryName", "[CriteriaField] = " & Forms!YourForm!CriteriaField) > 0 then
docmd.openform etc...
Else msgbox "No records were returned", vbinformation, "No Record Match"
End if

where ID is the record ID and [CriteriaField] is the field you are filtering the records on. If it is text, you will need to modify the DCount to
If dcount("[ID]", "qryQueryName", "[CriteriaField] = '" & Forms!YourForm!CriteriaField & "'") > 0 then

HTH
 

Users who are viewing this thread

Top Bottom