habbabub
02-11-2008, 08:32 PM
i have a form which has as button that opens a query
how can i make it so that if there arent any results from the query then a error message will pop up saying "no results found" and the table dosent show?
one way is to use the DCount function. create a query for your results and count the results *from the query*. if DCount = 0 then msgbox and exit sub.
habbabub
02-11-2008, 10:08 PM
how can i get into VB for a query???
neileg
02-13-2008, 12:47 AM
You need to test the DCount in the code that runs from your button. Look at Access help on DCount. You usually build the parameters for DCount so that it returns the same dataset as your query.
MStef
02-13-2008, 01:10 AM
Another way;
Make a Report on the query, and use "On No Data" properties (in report).
Look at "DemoRptNoDataA2000.mdb" (attachment).
habbabub
02-13-2008, 01:56 PM
Another way;
Make a Report on the query, and use "On No Data" properties (in report).
Look at "DemoRptNoDataA2000.mdb" (attachment).
im looking for an error message for the qurey itself, not a report
gemma-the-husky
02-14-2008, 04:32 PM
what they mean is, when you click your button, your code will be
docmd.openquery ("qryname")
so instead, have
if dcount("*","qrynaME")=0 then
MSGBOX("NO ITEMS")
else
docmd.openquery("qryname")
end if
habbabub
02-14-2008, 06:01 PM
my query has a critera so it is based on that, so if the criteria dosent match anything i want the error message box to come up
the code above dosent allow this
"if the criteria dosent match anything i want the error message box to come up"
it will. if the query works the way you want then...it works all the time. ask the query how many records there are any time you want. if there are records, do something. if there are no records supply the msg.
if you are saying you want to *change* the criteria every time that's different (and you haven't said this).
habbabub
02-14-2008, 09:06 PM
yes, i have a criteria that changes, according to what the user wants to type in .. so how can i do this?
neileg
02-15-2008, 01:11 AM
I usually prefer a combo box for user input so they can't enter an invalid criterion.
if you're not sure what neil's talking about you should search this site. not trying to be difficult - there are several threads discussing this and it'll probably be faster to search.