Keith
Registered User.
- Local time
- Today, 02:15
- Joined
- May 21, 2000
- Messages
- 129
I am creating a function to produce and email a report as a PDF file. The filter in the DoCmd.OpenReport does not work. The function works in that the files are saved correctly but each one contains all the records in qrySubs1 not those just relating to a branch. I would like some help please. The reports are produced correctly if I manually filter the query.
The function I have is;
The SQL for qry1 is;
The function I have is;
Code:
Public Function SubsDue()
Dim rs As Recordset
Dim db As DAO.Database
Dim Id As Integer
Dim strBranch, strfileName, strYear As String
On Error GoTo SubsDue_Error
strYear = Year(Now()) + 1
Set db = CurrentDb
Set rs = CurrentDb.OpenRecordset("qryBranchActive")
rs.MoveFirst
Do While Not rs.EOF
Id = rs!BranchID
Debug.Print Id
strBranch = rs!Branch_Name
Debug.Print strBranch
strfileName = "C:\submariners\Subs_Due\" & strYear & "\" & strBranch & ".pdf"
DoCmd.OpenReport "rptSubsDue", acViewPreview, "qrySubs1!BranchID =" & Id
DoCmd.OutputTo acOutputReport, "rptSubsDue", acFormatPDF, strfileName
'Code to Email report goes here
rs.MoveNext
Loop
On Error GoTo 0
Exit Function
SubsDue_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure SubsDue of Module mdlSubsDue"
End Function
The SQL for qry1 is;
Code:
SELECT tblBranch.BranchID, tblBranch.Branch_Name, tblMembers.MemberID, [LastName] & " " & [Initials] & " (" & [FirstName] & ")" AS [Member Name], IIf(IsNull([tblMembers].[NatSubsBranch]),"",IIf([tblMembers].[NatSubsBranch]=1,"SO to National",IIf([tblMembers].[NatSubsBranch]=[tblMemberBranch].[BranchID],"",DLookUp("Branch_Name","tblBranch","BranchID =" & [tblMembers].[NatSubsBranch])))) AS [Nat Subs Pd at Branch], tblMembers.Overseas, Format(IIf([Nat Subs Pd at Branch]<>" ",0,IIf([Overseas]=True,2,7.5)),"Currency") AS [Subs Due]
FROM tblBranch INNER JOIN (tblMembers INNER JOIN tblMemberBranch ON tblMembers.MemberID = tblMemberBranch.MemberID) ON tblBranch.BranchID = tblMemberBranch.BranchID
WHERE (((tblMembers.Status)=1 Or (tblMembers.Status)=2 Or (tblMembers.Status)=4))
ORDER BY tblMemberBranch.BranchID;
Last edited: