Open form only if a query returns a value

swarv

Registered User.
Local time
Today, 18:04
Joined
Dec 2, 2008
Messages
196
Hi all,

I have the following code:

Code:
SELECT absent.id, absent.Name, absent.Days, absent.notes, absent.comments, absent.backtowork, absent.certification
FROM absent WHERE (((absent.Name)=[forms]!frm_homepage.combo136.value) AND absent.backtowork = "No");
The above is in a query called qry_backisno
There is a form called frm_backisno which recordsource is qry_backisno

This is called from vba code as
Code:
DoCmd.OpenForm ("frm_backisno")

Now I only want the form to open is the query actually returns a value and not display a form with no records on it.

Is this possible?

Thanks
 
Test first:

If DCount("*", "qry_backisno") > 0 Then
 
excellent, thanks. works a treat.
 
Hello, I am trying to do the same thing but this is not working for me, what am i missing?
 
the first thing AnnPhil, is you need to be more specific. what's not working (or what is it doing that is wrong) and what have you tried already?
 
Another option is to test the result in the Forms On Load event with something like;

Code:
If Me.RecordSet.RecordCount = 0 then
     DoCmd.Close
     MsgBox "No Results for the search"
     Exit Sub
End If
 
Thanks so much John Big Booty, that worked perfect!!!!
 

Users who are viewing this thread

Back
Top Bottom