Error code solution

PJAY

New member
Local time
Today, 04:55
Joined
Dec 30, 2023
Messages
4
I have a database that consist of student student name in a particular school. At the end of every term the school send a news letter to every parent.
but my database generate all news letters as report contain each child name in one single pdf file.
now i am trying to generate the same pdf report file but this time i want it to be individual file for each child.
example if i a have 10 students, when i click a button the database should generate 10 pdf reports each file containing the information of one student and the file save withe the value of a field in the query.
this is the code:


Dim rpt As Report
Dim strFolderPath As String
Dim objFSO As Object
Dim objFolder As Object
Dim i As Integer


Set rpt = Reports("Nest-Term1-Bill") 'Replace "Report1" with the name of your report

strFolderPath = Environ("USERPROFILE") & "\Desktop\Note PDF\"

'Check if the folder exists, create it if not
Set objFSO = CreateObject("Scripting.FileSystemObject")
If Not objFSO.FolderExists(strFolderPath) Then
Set objFolder = objFSO.CreateFolder(strFolderPath)
End If

For i = 0 To rpt.Pages - 1

rpt.PrintOut acSelection, , , , i 'print the current page


Dim fileName As String

fileName = rpt.Controls("StudentFullName").Value 'Replace "NameField" with the name of the field in the page header that you want to use as the file name

DoCmd.OutputTo acOutputReport, "Nest-Term1-Bill", acFormatPDF, fileName & ".pdf"

Next i


MsgBox "PDF files have been created and saved in the Note PDF folder on the desktop.", vbInformation


and i am getting this error
error.jpg



please can anyone help me? i am a beginner in access programming.
 
Need to say on what line the error occurs? :(
I would use a recordset and issue the report per record.
 
Pat,
Could you explain how that form control gets populated within a loop please?
 
Thank you Pat
I suppose a Tempvar could be used instead, so the report only ever depends on that?
 
I was curious as to how you would imlplement your suggestion and can see I was on the right track. :)
The hidden report form is a neat idea.

I was always reluctant to tie a report to a form, in case the report could be used elsewhere.
For that reason I started using a few TempVars.
Then I found you can amend the qdf if a query, or just change the source yourself.
 
Thank you Tom,
I will review that link.
Happy New Year to you.
 

Users who are viewing this thread

Back
Top Bottom