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.Contr
ibutionAmo
unt) AS [Sum Of ContributionAmount], First(tblContributions.Con
tributionD
ate) AS [First Of ContributionDate], First(tblContributions.Mem
berID) AS [First Of MemberID]
FROM tblMembers INNER JOIN tblContributions ON tblMembers.MemberID=tblCon
tributions
.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.Contribu
tionDate Between #"
stFilter = stFilter & Me.txtDateFrom & "# And #" & Me.txtDateTo & "#"
stDateRange = Me.txtDateFrom & "# And #" & Me.txtDateTo & "#"
DoCmd.SetWarnings False
stDocName = "qryMailMerge4Contribution
sSend2Word
"
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