简体   繁体   中英

Populating a report in ms access via vba

So I have a stored procedure in my database which I run from MS access using pass through query which returns a table. I access the table using a recordset "rs". I want to loop through recordset and for each row I want to create an instance of the report and populate textboxes.

For example I want a report for each student that will have name, age, sex, etc. So it should be done by looping through recordset and creating a report for each student and filling in textboxes. I wrote this code to test for one textbox but have a strong feeling that I'm missing a lot. Any help would be very much appreciated

Dim i As Integer
i = 0

Do While Not rs.EOF
    Dim rtp(i) As Report_DecemberProject
    Set rpt(i) = New Report_DecemberProject
    rpt(i).Text55.Value = rs.Fields(3)
    rpt(i).Visible = True
    i = i + 1
Loop

Cannot programmatically set Value property of controls on report. Use BOUND report and controls and ForceNewPage property of Detail section to force page break after each record. Use Page Header section for information that must repeat for each page, such as label with report title and textbox with =Date(), etc.

To expand slightly on June 7's answer, it is the "Grouping" property of the report that lets you make a multi-page report with a new page started for each student. In the report properties, group on the student's (unique) ID. Then, as suggested above, use the ForceNewPage property in the Group header or footer to put each new student on a new page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM