Solved output report in continuous form with condition (1 Viewer)

freuzo

Member
Local time
Today, 09:31
Joined
Apr 14, 2020
Messages
98
Hi guys,
I have a form and a button with a code to output a report. It works great.
Now I need to print that report for many record. I built a continuous form wich display those records.
Also I have a control box in each record where the user can enter data (references).

What I want to achieve is that :
for each row in that form where me.reference is not null,
output the report

I'm not good yet with "for each" codes

my output code
Code:
sub outBtn()
dim FldrPath as string
dim FileName as string
dim FilePath as sting

FldrPath = "D:\Report"
FileName = "report_" & format(now,"yymmddhhmmss")
FilePath = fldrPath & "\" & Filename & ".pdf"

DoCmd.OpenReport "EtReport", acViewPreview, , "id_subact=" & Me.id_subact, acHidden
DoCmd.OutputTo acOutputReport, "EtReport", acFormatPDF, Filepath
DoCmd.Close acReport, "EtReport", acSaveNo

end sub

Thanks for yours suggestions
 

theDBguy

I’m here to help
Staff member
Local time
Today, 01:31
Joined
Oct 29, 2018
Messages
21,485
Hi. One thing you could try is open the report with a filter first before outputting it.
 

freuzo

Member
Local time
Today, 09:31
Joined
Apr 14, 2020
Messages
98
hi,
I think it's already done with this line in the code

DoCmd.OpenReport "EtReport", acViewPreview, , "id_subact=" & Me.id_subact, acHidden
 

theDBguy

I’m here to help
Staff member
Local time
Today, 01:31
Joined
Oct 29, 2018
Messages
21,485
hi,
I think it's already done with this line in the code
Sorry, I missed that. So, whatever is shown in the report when it's open with a filter is not what is showing in the PDF? Is that what you're saying?
 

freuzo

Member
Local time
Today, 09:31
Joined
Apr 14, 2020
Messages
98
The report and the pdf are fine,
Now, I need it to work on each row in a continuous form, so the user doesn't have to click on each row to output them
 

theDBguy

I’m here to help
Staff member
Local time
Today, 01:31
Joined
Oct 29, 2018
Messages
21,485
The report and the pdf are fine,
Now, I need it to work on each row in a continuous form, so the user doesn't have to click on each row to output them
Okay, so I think that's where I was trying to go earlier. Open the report with an appropriate filter to match the records on your form.
 

freuzo

Member
Local time
Today, 09:31
Joined
Apr 14, 2020
Messages
98
I think I understand what you mean. I'm going to try
 

freuzo

Member
Local time
Today, 09:31
Joined
Apr 14, 2020
Messages
98
so, the source of the report will be the same source as my continuous form but filtered by me.reference.
and I will remove the where clause here
DoCmd.OpenReport "EtReport", acViewPreview, , "id_subact=" & Me.id_subact, acHidden
hope I'll get it done
 

theDBguy

I’m here to help
Staff member
Local time
Today, 01:31
Joined
Oct 29, 2018
Messages
21,485
so, the source of the report will be the same source as my continuous form but filtered by me.reference.
and I will remove the where clause here

hope I'll get it done
Let us know how it goes.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 04:31
Joined
May 21, 2018
Messages
8,547
One easy way is to make a query that returns the IDs of those records where the reference is not null

dim rs as dao.recordset
dim id as long
set rs = currentdb.openrecordset ("qryWithReference")

do while not rs.eof
id = rs!subAct
'put your export code here
rs.moveNext
loop
 

freuzo

Member
Local time
Today, 09:31
Joined
Apr 14, 2020
Messages
98
One easy way is to make a query that returns the IDs of those records where the reference is not null

dim rs as dao.recordset
dim id as long
set rs = currentdb.openrecordset ("qryWithReference")

do while not rs.eof
id = rs!subAct
'put your export code here
rs.moveNext
loop

Thank you for the code. I'll try it.
 

freuzo

Member
Local time
Today, 09:31
Joined
Apr 14, 2020
Messages
98
One easy way is to make a query that returns the IDs of those records where the reference is not null

dim rs as dao.recordset
dim id as long
set rs = currentdb.openrecordset ("qryWithReference")

do while not rs.eof
id = rs!subAct
'put your export code here
rs.moveNext
loop
Your code helped me get it done. But what is really wonderful is that it send me to learn about manipulating recordsets in VBA, which is really powerful and helpful.
Thanks a lot.
 

Users who are viewing this thread

Top Bottom