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?
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