Hi, i have been trying to print single PDFs from a report but all i can manage is to print the full report into multiple files, not sure what i'm doing wrong.
Can someone point me in the right direction?
this is the basic VBA code im using
Private Sub cmdSaveAsPDF_Click()
Dim qdf As DAO.QueryDef
Dim strSQL As String
Dim strPathName As String
Dim blRet As Boolean
Dim rs As Recordset
Dim stDocName As String
Dim strSavedSQL As String
If Me.Dirty Then Me.Dirty = False
stDocName = "3FolhaHorasQRT"
strSQL = "SELECT Dados.NFicha FROM Dados WHERE (((Dados.SelectedPrint)=True));"
Set rs = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot)
If rs.RecordCount < 1 Then
MsgBox "Nothing found to process", vbCritical, "Error"
Exit Sub
End If
''CreateFolder CurrentProject.Path & "\TesteF"
' store the current SQL
Set qdf = CurrentDb.QueryDefs("FQR")
strSavedSQL = qdf.SQL
qdf.Close
Set qdf = Nothing
Do
Set qdf = CurrentDb.QueryDefs("FQR")
strSQL = Left(strSavedSQL, InStr(strSavedSQL, ";") - 1) & " and (Dados.NFicha = " & rs!NFicha & ");"
qdf.SQL = strSQL
qdf.Close
Set qdf = Nothing
' put in the same folder as the database
strPathName = CurrentProject.Path & "\TesteF" & rs!NFicha & ".pdf"
DoCmd.OutputTo acOutputReport, stDocName, acFormatPDF, strPathName
rs.MoveNext
Loop Until rs.EOF
rs.Close
Set rs = Nothing
' restore the SQL
Set qdf = CurrentDb.QueryDefs("FQR")
qdf.SQL = strSavedSQL
qdf.Close
Set qdf = Nothing
End Sub
Can someone point me in the right direction?
this is the basic VBA code im using
Private Sub cmdSaveAsPDF_Click()
Dim qdf As DAO.QueryDef
Dim strSQL As String
Dim strPathName As String
Dim blRet As Boolean
Dim rs As Recordset
Dim stDocName As String
Dim strSavedSQL As String
If Me.Dirty Then Me.Dirty = False
stDocName = "3FolhaHorasQRT"
strSQL = "SELECT Dados.NFicha FROM Dados WHERE (((Dados.SelectedPrint)=True));"
Set rs = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot)
If rs.RecordCount < 1 Then
MsgBox "Nothing found to process", vbCritical, "Error"
Exit Sub
End If
''CreateFolder CurrentProject.Path & "\TesteF"
' store the current SQL
Set qdf = CurrentDb.QueryDefs("FQR")
strSavedSQL = qdf.SQL
qdf.Close
Set qdf = Nothing
Do
Set qdf = CurrentDb.QueryDefs("FQR")
strSQL = Left(strSavedSQL, InStr(strSavedSQL, ";") - 1) & " and (Dados.NFicha = " & rs!NFicha & ");"
qdf.SQL = strSQL
qdf.Close
Set qdf = Nothing
' put in the same folder as the database
strPathName = CurrentProject.Path & "\TesteF" & rs!NFicha & ".pdf"
DoCmd.OutputTo acOutputReport, stDocName, acFormatPDF, strPathName
rs.MoveNext
Loop Until rs.EOF
rs.Close
Set rs = Nothing
' restore the SQL
Set qdf = CurrentDb.QueryDefs("FQR")
qdf.SQL = strSavedSQL
qdf.Close
Set qdf = Nothing
End Sub