Hi,
I have a code which is running fine in creating a single file on a grouped field. The problem is I have more than 20000 records having
DeptID, empId, JoinDt as 3 fields(i have kept sample fields).
I have grouped on DeptId in which at least 20 records of employees for each Department.
I am trying to print a separate file for each department as file name.
When I execute the code every time its asking to enter the DeptId for each and every record...and creating only one DeptID file which appears first.
As a newbie I dont know how to modify the code. Please help. Thank you
Private Sub Command7_Click()
Dim rst As Recordset
Dim db As Database
Dim strSQL As String
Set db = CurrentDb()
strSQL = "SELECT [MyTbl].DeptID, [MyTbl].empID, [MyTbl].joindt FROM [MyTbl]"
Set rst = db.OpenRecordset(strSQL)
rst.MoveFirst
Do Until rst.EOF
DoCmd.OpenReport "DeptRpt", acViewPreview, , "DeptID = " & rst!DeptID
DoCmd.OutputTo acOutputReport, "DeptRpt", acFormatPDF, "C:\test" & rst!DeptID & ".pdf"
DoCmd.Close acReport, "DeptRpt"
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
strSQL = ""
End Sub