View Full Version : Open form only if a query returns a value


swarv
02-17-2009, 07:44 AM
Hi all,

I have the following 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
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

pbaldy
02-17-2009, 07:57 AM
Test first:

If DCount("*", "qry_backisno") > 0 Then

swarv
02-17-2009, 08:03 AM
excellent, thanks. works a treat.

AnnPhil
03-01-2009, 12:10 PM
Hello, I am trying to do the same thing but this is not working for me, what am i missing?

wiklendt
03-01-2009, 12:22 PM
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?

John Big Booty
03-01-2009, 01:12 PM
Another option is to test the result in the Forms On Load event with something like;


If Me.RecordSet.RecordCount = 0 then
DoCmd.Close
MsgBox "No Results for the search"
Exit Sub
End If

AnnPhil
03-01-2009, 02:46 PM
Thanks so much John Big Booty, that worked perfect!!!!

John Big Booty
03-01-2009, 02:54 PM
Excellent :)