loop through records in an Access form

Stevep4

New Member
Joined
Aug 28, 2015
Messages
34
I literally did this 15 years ago in Access, but have forgotten. I have a form connected to a table. I want code that will simply look at the filelds in the table, loop through them so that I can run a report for each records. Here's the order I want to do things in.

Store 1 is in the form
A report is exported for store 1 (the query the report is running off of is looking at the form field, which shows store 1)
Store 2 is then populated in the form and a second report is exported
and so on.

I know how to export a report using VBA, I'm just not show how to get the form to loop through all the records.

Thanks,
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
I would say basing the report on the form value isn't the most efficient way to do this, as you need to wait for the form to load each record etc. I would normally use a TempVar or build the report data source on the fly (both while looping through a recordset).

Using the form:


Code:
Dim fname As String


DoCmd.GoToRecord , , acFirst
With Me.Recordset
Do Until .AbsolutePosition = .RecordCount - 1
    DoCmd.GoToRecord , , acNext
    fname = [COLOR=#ff0000][B] 'Build unique filename[/B][/COLOR]
    DoCmd.OutputTo acOutputReport, "MyReport", acFormatPDF, "Fname"
Loop
End With
 
Upvote 0
sorry: DoCmd.OutputTo acOutputReport, "MyReport", acFormatPDF, "Fname" was wrong:


DoCmd.OutputTo acOutputReport, "MyReport", acFormatPDF, Fname </pre>
 
Upvote 0

Forum statistics

Threads
1,214,615
Messages
6,120,538
Members
448,970
Latest member
kennimack

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top