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 = "InvTotal" strSQL = "SELECT Contracts.OrderID FROM Contracts WHERE (((Contracts.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 & "\Contracts" ' store the current SQL Set qdf = CurrentDb.QueryDefs("Invoices") strSavedSQL = qdf.SQL qdf.Close Set qdf = Nothing Do Set qdf = CurrentDb.QueryDefs("Invoices") strSQL = Left(strSavedSQL, InStr(strSavedSQL, ";") - 1) & " and (Contracts.OrderID = " & rs!OrderID & ");" qdf.SQL = strSQL qdf.Close Set qdf = Nothing ' put in the same folder as the database strPathName = CurrentProject.Path & "\Contracts\" & rs!OrderID & ".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("Invoices") qdf.SQL = strSavedSQL qdf.Close Set qdf = Nothing End Sub
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
Connect with Certified Experts to gain insight and support on specific technology challenges including:
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE