Loop Through Table

toleafs

Active Member
Joined
Jun 27, 2005
Messages
498
Hi
Any help is greatly appreciated. What I would like to do is the following;

I have a table 'tblLRF' with a 'Field1Name' with over 150 records, I also have an unbound form called 'frmBuild' that contains an unbound text field (txtReport) as well a a Button that when click runs macros to populate other tables in the database based on the 'txtReport' field in the form. What happens now is that one by one I need to populate the 'txtReport' field in the form and click the button. Is there a way to automatically populate the 'txtReport' field with the record in 'tblLRF' and run the macros and have it cylcle through the table until all records have been completed?

Hope this makes sense. Thanks in advance for your help.
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
I use DAO but you can use ADO too. Make sure your database has the appropriate references.

' declare variables
Dim dbMe as Database
Dim rsLRF as DAO.Recordset

' open recordset
Set dbMe = CurrentDb
Set rsLRF + dbMe.OpenRecordset("tblLRF")

' loop through and run the macro for each value in the table
With rsLRF
.MoveFirst
Do Until .EOF
' assuming this code is being run from frmBuild ...
' put the value in the text box
[txtReport] = !Field1Name
' and run the macros
DoCmd.RunDataMacro(MacroName)
' move to the next record
.MoveNext
Loop
End With

' deallocate recordset objects
Set rsLFR = Nothing
Set dbMe = Nothing

Hope this helps!

UC
 
Upvote 0

Forum statistics

Threads
1,221,783
Messages
6,161,938
Members
451,730
Latest member
BudgetGirl

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