Check if Query has entry's

ramasule

Registered User.
Local time
Yesterday, 21:10
Joined
Mar 13, 2007
Messages
33
Hello,

I could use some help on the following code and event
I wish to run this when a Certain form opens, and everyday at 7:00 am.

Run query
If query returns results display query (or another form)
Else Exit Form

I tried running something like

IIf (testquery <> Empty, 1, 0)
But it always returns testquery is empty.

Anyhelp would be appriciated

Thank you,

Derek L
 
How about a Dcount to count the records in the query. If the Dcount result is > 0 then your query has records.
 
May I ask how I emplement this "Dcount"
You'll have to excuse me I am very green to Access.
 
Have you looked up DCount() in VBA help yet?
 
Yeah the computer I have access on was not available to me at the time.
I have looked it up and got it working now.
Thank you Dwight

Derek L
 
I try
Active = DCount("[PermitNumber]", "Active Permits", "[PermitNumber] <> 0")

Active is a Number Field of a Table PermitOverview
When I run the code it gives me

Run-Time error '2448':
You can't assign a value to this object.

What am I missing here?

Derek L
 
What happened to the original requirement?
Run query
If query returns results display query (or another form)
Else Exit Form
Code:
If DCount("[PermitNumber]", "Active Permits", "[PermitNumber] <> 0") > 0 Then
display query (or another form)
Else Exit Form
 
The origanol part works im trying to return the number of counts to
the form that called it.
 
Assign it to a control on your form rather than a field in a table.
Code:
Me.ControlName = DCount("[PermitNumber]", "Active Permits", "[PermitNumber] <> 0")
...using your control name of course.
 
Thanks RuralGuy I will try it tonight after supper
 
Nope I assigned it to
Me.Active = Dcount( ....)

Gave me the
You cant assin a value to this object

Funny thing is when I go to the table rename the object
then recode everything it has no problem.
 
Last edited:
Ok I linked the code to a button instead of
On Open ...

and it worked.

I dont know why it wouldnt work on form open.

Anyways thanks for your patience and time,

Derek L
 
The Open event is too early to reference controls on your form. Use the Load event instead.
 

Users who are viewing this thread

Back
Top Bottom