subform field reference

S

Scafidel

Hello,
I have a form (Formname) with a query subform (Subform_Query) that I use to
merge information to a Word doc. via bookmarks. The merge uses information
from the main form and works fine for the first field, [Person] of the
subform, but I can't figure out how to call the next field or record under
[Person] and the next, etc. I use this code for the first field.

This works for first instance.
.ActiveDocument.Bookmarks("Person1Bookmark").Select
..Selection.Text = (DLookup("Person", "Subform_Query",
"[ID]=(Forms!Formname!ID)"))

How do I name or reference the next "Person"?
Thanks
 
P

pietlinden

Hello,
I have a form (Formname) with a query subform (Subform_Query) that I use to
merge information to a Word doc. via bookmarks.  The merge uses information
from the main form and works fine for the first field, [Person] of the
subform, but I can't figure out how to call the next field or record under
[Person] and the next, etc.  I use this code for the first field.

This works for first instance.
      .ActiveDocument.Bookmarks("Person1Bookmark").Select
.Selection.Text = (DLookup("Person", "Subform_Query",
"[ID]=(Forms!Formname!ID)"))

How do I name or reference the next "Person"?
Thanks

one way is to open a recordset based on the subform's data and pass
the whole recordset to Word and convert it to a table.
 
J

JString

I haven't ever tried working with mail merges using Access, so this may not
be helpful, but here's how I usually loop through a subform's controls:

for each ctl in forms("main form").controls("sub form control").form.controls
returnval = ctl
perform some action here
next

note that this example assumes your subform is actually a query not an
actual form. If it is a form and it has any labels or other controls that
are not text boxes it probably won't work without additional code.

The other option would be to
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top