Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you Loop through a subform

Status
Not open for further replies.

Toxodont

IS-IT--Management
Jul 12, 2002
52
0
0
CA
I have a subform, which displays in datasheet view (based off a query). I need a piece of code which will loop through all records in the subform.

What the program is supposed to do is go to the main form and throw some info into a word file, then go to the subform (which queries for all related records) and then throw all the related info into the same word file.

The following code works fine. This is taking the main forms info and throwing it into the word file:

.ActiveDocument.Bookmarks("bmk_complainant").Select
.Selection.Text=CStr(Forms!frm_complaint!Complainant_Name))

This next part is where it gets tricky. I need to somehow tell the program to increment the bookmark name (make the name a variable ?) and then go through the subform record by record until all the info it thrown into the word file. So, the program would basically be doing this:

Bookmark variable would be incremented.

.ActiveDocument.Bookmarks("bmk_complainant2").Select
.Selection.Text = (CStr(Forms!frm_complaint![subfrm_qryRelated].Form.Complainant_Name))

Then it would go to the next record, incrementing the bookmark variable again as well.

.ActiveDocument.Bookmarks("bmk_complainant3").Select
.Selection.Text = (CStr(Forms!frm_complaint![subfrm_qryRelated].Form.Complainant_Name))

So that's the idea anyways. The main problems are making a incrementable variable for the bookmark name, and telling it to move to the next record in the subform.

Any help is appreciated :O)
 
Hi

Sorry, did not follow all of you stuff about bookmarks, are you talking about bookmarks in Access or bookmarks in word ?

Anyway, to move through the subform recordset, you can use recordsetclone

from within the sub form itself

Me.RecordsetClone.MoveFirst
Do Until Me.RecordsetClone.EOF
Me.BookMark = Me.RecordsetClone.Bookmark
Me.RecordsetClone.MoveNExt
Loop

if you want to do this from the main form

Me.MySubFormControl.FORM.RecordsetClone.MoveFirst
Do Until Me.MySubFormControl.RecordsetClone.EOF
Me.MySubFormControl.BookMark = Me.MySubFormControl.RecordsetClone.Bookmark
Me.MySubFormControl.RecordsetClone.MoveNExt
Loop

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
I apologize. The bookmarks are for MS word. That's how the code knows where to throw the information in the word file.

Thank you for the response as well! I will go try that now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top