View Full Version : Supressing a query


Hudson40
04-15-2008, 06:04 AM
Hi

I have a query that uses 2 variables from a form. All the query is doing is checking whether the 2 variables exist in a table. 99% of the time there will not be a match. Does anybody know how you supress the query from being displayed when no results are found?

Thanks

Andrew

neileg
04-15-2008, 06:20 AM
Before you run the query, use DCount() to do the same search. If the count is 0, don't run the query.

Hudson40
04-15-2008, 07:01 AM
Hi

Thanks for reply and bear with me as I haven't used access for over a year.

Tried the following code:

Dim vInvNo As Variant
Dim VPayee As Variant
Dim Count1 As Long
Dim Count2 As Long

vInvNo = [Forms]![frmInvoiceInput]![Text60].Value
VPayee = Me.[Combo52].Value

Count1 = DCount("Amount", "tblInvoices", "Payee = vPayee")
Count2 = DCount("Amount", "tblInvoices", "Invoice No(s) = vInvNo")

If Count1 > 0 And Count2 > 0 Then
DoCmd.OpenQuery "qryInvoiceCheck"
End If


Basically I'm having probs with the "Payee = vPayee" part in count1 ie how do you include variable in the function?

Cheers

Andrew