Linking textboxes to a subform

H

hughgoagogo

I have a form with a subforn linked to a Query, also I have textboxes linked
to the same Query.
How do I make the Text boxes show the same line I select within the subform?
 
T

Tom van Stiphout

On Tue, 7 Jul 2009 21:32:01 -0700, hughgoagogo

I understand you have a form with the same RecordSource as its
subform. The subform is likely in datasheet view and is used as a list
of records to select from. When the record selector of a row is
double-clicked, you want the form to reflect that row.
Yes, that can be done with a few lines of VBA. In the subform's
Form_DblClick event write:
(off the top of my head)
Me.Parent.Bookmark = Me.RecordsetClone.Bookmark

-Tom.
Microsoft Access MVP
 
D

Dirk Goldgar

Tom van Stiphout said:
On Tue, 7 Jul 2009 21:32:01 -0700, hughgoagogo

I understand you have a form with the same RecordSource as its
subform. The subform is likely in datasheet view and is used as a list
of records to select from. When the record selector of a row is
double-clicked, you want the form to reflect that row.
Yes, that can be done with a few lines of VBA. In the subform's
Form_DblClick event write:
(off the top of my head)
Me.Parent.Bookmark = Me.RecordsetClone.Bookmark


Are you sure that will work, Tom? It seems to me that the parent form's
Bookmark will not be compatible with the subform's Bookmark, because their
recordsets are opened independently of each other (even though they are
based on the same query).

If the above line of code doesn't work, you can use the parent form's
Recordset property to locate the matching record, by doing a FindFirst on
the matching primary key:

Me.Parent.Recordset.FindFirst "ID=" & Me.ID

.... where "ID" is the name of the form and subform's primary key field. If
that field is a text field, you will have to enclose it in quotes; e.g.,

Me.Parent.Recordset.FindFirst "ID=" & Chr(34) & Me.ID & Chr(34)
 

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