DoCmd.OpenReport not working right with WHERE clause
15 pts.
0
Q:
DoCmd.OpenReport not working right with WHERE clause
I have looked all over and seen hundreds of questions about this command, but no answers. It seems like the most basic thing you can do with combo boxes, so I'm baffled that it doesn't work.

Here is my VBA Code:

Option Compare Database

Private Sub cboFundNumbers_AfterUpdate()
Const strFormName As String = "Fund Number 2"
Const strWhereClause As String = "A.Fundno='7225'"
DoCmd.OpenReport strFormName, acPreview, , strWhereClause
End Sub

Private Sub cboFundNumbers_BeforeUpdate(Cancel As Integer)

End Sub
******
And here is the SQL Code that the Form depends on:

SELECT B.Owner, Sum(B.AvLand) AS SumOfAvLand, Sum(B.AvImpv) AS SumOfAvImpv, Sum(A.TaxAmt1) AS SumOfTaxAmt1, Sum(A.TaxAmt2) AS SumOfTaxAmt2, Sum(A.Unpaid1) AS SumOfUnpaid1, Count(A.Napn) AS CountOfNapn
FROM [Solano Delinquency 2009] AS A, [Solano Roll 2008] AS B
WHERE A.Napn=B.Napn AND A.Fundno="7225"
GROUP BY B.Owner;

I have tried several different ways of doing this: deleting the WHERE clause from the SQL code (doesn't work), taking the where clause out of the VBA code (does work), leaving both in like shown (doesn't work), using only one condition (doesn't work). I eventually want to take the data in from the combo box, but I can't even select records with VBA yet.

Any ideas on what might be wrong?
ASKED: Apr 1 2009  10:20 PM GMT
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
0
29820 pts.
0
A:
 RATE THIS ANSWER
0
Click to Vote:
  •   0
  •  0
  • AddThis Social Bookmark Button
From the discussion below,

It seems that Access executes the base query first, and then apply the dynamic ‘where’ condition, and thus you can only filter by columns included in your select list.

This worked:

SELECT B.Owner, A.Fundno,Sum(B.AvLand) AS SumOfAvLand, Sum(B.AvImpv) AS SumOfAvImpv, Sum(A.TaxAmt1) AS SumOfTaxAmt1, Sum(A.TaxAmt2) AS SumOfTaxAmt2, Sum(A.Unpaid1) AS SumOfUnpaid1, Count(A.Napn) AS CountOfNapn
FROM [Solano Delinquency 2009] AS A INNER JOIN [Solano Roll 2008] AS B
ON A.Napn=B.Napn
GROUP BY B.Owner,A.Fundno;
Last Answered: Apr 2 2009  0:02 AM GMT by Carlosdl   29820 pts.
0
0
Discuss This Answer:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _



_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

Carlosdl   29820 pts.  |   Apr 1 2009  11:21PM GMT

Is Fundno a string ?

Could you try this SQL (with the same VBA code you posted): ?

SELECT B.Owner, Sum(B.AvLand) AS SumOfAvLand, Sum(B.AvImpv) AS SumOfAvImpv, Sum(A.TaxAmt1) AS SumOfTaxAmt1, Sum(A.TaxAmt2) AS SumOfTaxAmt2, Sum(A.Unpaid1) AS SumOfUnpaid1, Count(A.Napn) AS CountOfNapn
FROM [Solano Delinquency 2009] AS A INNER JOIN [Solano Roll 2008] AS B
ON A.Napn=B.Napn
GROUP BY B.Owner;

When you say “doesn’t work”, do you get some error message ? or a prompt asking for a parameter ?

On the other hand, I’m not an access expert, so I don’t really know how Access manage these dynamic ‘where’ clauses, but if it executes the base query first, and then apply the dynamic ‘where’ condition, it is possible that you can only filter by columns included in your select list, so, I would also try this:

SELECT B.Owner, A.Fundno,Sum(B.AvLand) AS SumOfAvLand, Sum(B.AvImpv) AS SumOfAvImpv, Sum(A.TaxAmt1) AS SumOfTaxAmt1, Sum(A.TaxAmt2) AS SumOfTaxAmt2, Sum(A.Unpaid1) AS SumOfUnpaid1, Count(A.Napn) AS CountOfNapn
FROM [Solano Delinquency 2009] AS A INNER JOIN [Solano Roll 2008] AS B
ON A.Napn=B.Napn
GROUP BY B.Owner,A.Fundno;

Regards,

 

Pubfin   15 pts.  |   Apr 1 2009  11:38PM GMT

A.Fundno is a string.

The second one worked! Thank you! I am going to hang this in big bold letters on my cube:

“you can only filter by columns included in your select list”

 
0