Advertisement

01.18.2007 at 02:49PM PST, ID: 22128194
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.0

Filtering Grouped Queries

Asked by yddadsjd95 in Microsoft Access Database

Tags: ,

Hi Gang, I have a routine that allows the user to determine which members who have given contributions will be sent to MS Word to have a Mail Merge letter printed on their behalf. I want to be able to send a date filter to the query that checks for contributions given between two dates (DateFrom, DateTo which is entered by the user via the form that calls the query and does the mail merge). My problem is that the query is grouped on the sum of the contributions that were given. This query gives the sum of all contributions, but I want the user to be able to determine which dates will be used. I have found out after a few hours of working on this that group-by queries do not take WhereCondition statements. So I need some help in filtering the data. Here is the SQL for the query:

SELECT DISTINCTROW tblMembers.Member, tblMembers.Title, tblMembers.IncludeInMM, tblMembers.Active, tblMembers.FirstName, tblMembers.LastName, tblMembers.StreetAddress, tblMembers.ApartmentNum, tblMembers.City, tblMembers.State, tblMembers.ZipCode, Sum(tblContributions.ContributionAmount) AS [Sum Of ContributionAmount], First(tblContributions.ContributionDate) AS [First Of ContributionDate], First(tblContributions.MemberID) AS [First Of MemberID]
FROM tblMembers INNER JOIN tblContributions ON tblMembers.MemberID=tblContributions.MemberID
GROUP BY tblMembers.Member, tblMembers.Title, tblMembers.IncludeInMM, tblMembers.Active, tblMembers.FirstName, tblMembers.LastName, tblMembers.StreetAddress, tblMembers.ApartmentNum, tblMembers.City, tblMembers.State, tblMembers.ZipCode
HAVING (((tblMembers.IncludeInMM)=True));


And here is the code that I am using to attempt to filter the data (This is a long routine, so I have cut and pasted only the relevant part.):

Private Sub btnMailMerge_Click()
 
    Dim stFilter As String
    Dim stDocName As String
    Dim strSQL As String
    Dim strMergeLetterName As String
    Dim lngInclude As Long
    Dim recClone As DAO.Recordset
    Set recClone = Me.RecordsetClone()
   
        stFilter = "qryContributions.ContributionDate Between #"
        stFilter = stFilter & Me.txtDateFrom & "# And #" & Me.txtDateTo & "#"
        stDateRange = Me.txtDateFrom & "# And #" & Me.txtDateTo & "#"
   
        DoCmd.SetWarnings False
        stDocName = "qryMailMerge4ContributionsSend2Word"
        DoCmd.OpenQuery stDocName, acNormal, acEdit, WhereCondition:=stFilter
        Form.Refresh
        DoCmd.SetWarnings True

    End Sub

When my program gets to the DoCmd.OpenQuery line I get the following compile error:

"Wrong number of arguments or invalid property assignment"

and I assume that it is referring to the "WhereCondition:=stFilter" argument.

I want the query to run so that it will create the data that I need as my Word Mail Merge record source.

Any suggestions?

Thanks in advance,

David
Start Free Trial
 
Loading Advertisement...
 
[+][-]01.21.2007 at 12:10AM PST, ID: 18358974

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Microsoft Access Database
Tags: create, filter
Sign Up Now!
Solution Provided By: YaacovKlapisch
Participating Experts: 1
Solution Grade: A
 
 
[+][-]01.21.2007 at 04:39AM PST, ID: 18359408

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32