DoCmd.OutputTo in a Loop

Please show the most recent version of the code you have.
 
Hey Guys, I changed my code up a bit.
Private Sub Form_Load()
Dim strName As String
Dim rs As DAO.Recordset
Dim currentCount As String
Dim totalCount As String
Dim strPath As String
Dim SQL As String



Set rs = CurrentDb.OpenRecordset("DebtMasters")
strName = DLookup("NameNo", "DebtMasters")
currentCount = 0
totalCount = "SELECT count(NameNo) FROM DebtMasters"
strPath = "C:\Test\"
'' SQL = DLookup("NameNo", "DebtMasters")
Set strName = Forms!InvoicesDue!txtNameNo

Do While Not rs.EOF
If currentCount < totalCount Then
DoCmd.OutputTo acOutputForm, "InvoicesDue", FormatPDF.PDF, strPath & strName & ".pdf", False, "", 0
rs.MoveNext

End If

Loop
rs.Close


End Sub


I get a compile error saying object required.

Can anywone please explain to me why this is happening?
 
Last edited:
You're using "Set" to assign to a non-Object datatype. 'strName' is declared as a string. Try . . .
Code:
strName = Forms!...

Also, see the "#" number sign up on the little toolbar in the post window? Next time highlight your code and hit that button, and your code gets offset and your indents are preserved, like . . .
Code:
Private Sub Form_Load()
    Do While Not rs.EOF
        If currentCount < totalCount Then
            DoCmd.OutputTo acOutputForm, "InvoicesDue", FormatPDF.PDF, strPath & strName & ".pdf", False, "", 0
            rs.MoveNext
        End If
    Loop
    rs.Close
End Sub
. . . which is way easier to understand than . . .
Private Sub Form_Load()
Do While Not rs.EOF
If currentCount < totalCount Then
DoCmd.OutputTo acOutputForm, "InvoicesDue", FormatPDF.PDF, strPath & strName & ".pdf", False, "", 0
rs.MoveNext
End If
Loop
rs.Close
End Sub
 
thanks, i didnt know that...i figured out the code to print all the pdf's...now i just need to populate the forms..would you like to see the code?
 

Users who are viewing this thread

Back
Top Bottom