У меня есть запрос, который фильтрует детали и перечисляет их по номеру детали.
Я сделал отчет, который создает PDF в зависимости от количества строк в запросе. Этот запрос содержит около 50 строк, поэтому PDF имеет 50 страниц.
Я хочу напечатать каждую страницу отдельно и назвать этот файл в зависимости от номера детали.
Следующий код печатает все 50 страниц.
Private Sub FFS()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim rs1 As DAO.Recordset
Dim MyFileName As String
Dim mypath As String
Dim tempRev As String
Dim tempRev2 As String
'insert file path ending with a dash
mypath = "C:\Users\sjackson\Desktop\pin sheets seth copy\save 1\"
Set db = CurrentDb()
'grabs the part number of the product from SETHQUERY
Set rs = db.OpenRecordset("SELECT DISTINCT [PIN PRODUCT] FROM [SETHQUERY]", dbOpenSnapshot)
'grabs the drawing revision ex. "A"
Set rs1 = db.OpenRecordset("SELECT [REVISION NO] FROM [SETHQUERY]", dbOpenSnapshot)
Do While Not rs.EOF
tempRev = rs1("[REVISION NO]") ' grabs the revision for that record set
tempRev2 = Mid(tempRev, 2, 1) ' removes the quotes from the revision, ex. "A" becomes A
'creates the file name ex. 123456-0000A
MyFileName = rs("[PIN PRODUCT]") & tempRev2 & ".pdf"
DoCmd.OpenQuery "SETHQUERY" ' why is the query opened and then closed right afterwards?
DoCmd.Close acQuery, "SETHQUERY", acSaveYes
'DoCmd.OpenReport "SETHREPORT", acViewPreview ' (option 1)opens the ENTIRE report
'(option 2)opens the single report where PIN PRODUCT equals the current PIN PRODUCT
DoCmd.OpenReport "SETHREPORT", acViewPreview, , "[PIN PRODUCT]=" & rs("[PIN PRODUCT]")
DoCmd.OutputTo acOutputReport, "", acFormatPDF, mypath & MyFileName 'file path
' saves the entire report when using option 1,
' and saves a blank report when using option 2
DoCmd.Close acReport, "SETHREPORT", acSaveYes
DoEvents
rs.MoveNext ' moves to next product pin
rs1.MoveNext ' moves to next drawing revision
Loop
rs.Close
Set rs = Nothing
Set rs1 = Nothing
Set db = Nothing
End Sub
Я изменил код, чтобы открыть только один отчет на основе номера детали этой строки, но при сохранении отчет пуст. Я не могу заставить строку DoCmd.OpenReport правильно работать с моим фильтром WHERE.