DoCmd.OpenReport not working right with WHERE clause

15 pts.
Tags:
Microsoft Access 2003
VBA
WHERE statement
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?

Answer Wiki

Thanks. We'll let you know when a new response is added.

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;

Discuss This Question: 3  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • carlosdl
    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,
    70,220 pointsBadges:
    report
  • Pubfin
    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"
    15 pointsBadges:
    report
  • Watyer
    try acViewPreview (with the View in it). I made the same problem earlier this week and spent hours trying to find my problem :-)
    10 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following