On Sun, 14 Nov 2004 21:54:14 GMT, "Zeeshan Iqbal via AccessMonster.com"
<fo***@AccessMonster.com> wrote:
hi,
im trying to design a form with two subforms. subforms no.1 (orders) is connected to the main form by customer ID and i dont know how i can connect another subform (order details)to the first subform(orders), so that when i enter a customer id i get the orders related to that customer in subform no.1 and order details related to that order in subform no.2. please message me if some one knows how to do that
*****************************************
* This message was posted via http://www.accessmonster.com
*
* Report spam or abuse by clicking the following URL:
* http://www.accessmonster.com/Uwe/Abu...3a020421f80e27
*****************************************
First, if there's some way you can get your news interface to wrap text, that
would be really helpful. What most of us see is one veeryyyyyy looong line
with your entire question in it.
What your asking for is a pattern I use often because it's the only way to
display a one-to-many relationship on a form where both tables are shown as
continuous, multi-row. It's not hard to do, there's just a little trick to
making it work.
First, you need to know that it's possible to use a control name as the master
in the master/child link. It doesn't need to be a field in a table. That
means you can place an unbound control on the container form, and link the
second subform based on the name of that controls.
Next, you need some way to get the value of the control on the container form
to be the id of the current record in the first subform. You do that using
the OnCurrent event handler of the first subform, and copying the value of the
id to the field on the container (its parent).
There's one final issue, though, and that is that the subforms are initialized
-before- the parent, so the first time the Current event fires, it will fail.
You can use On Error Resume next to ignore the error, but then the id control
in the container won't be initialized until the user moves to a new record.
The way I get around this is that the OnOpen handler of the first subform
copies its RecordSource to a variable, and sets the Recordsource to a blank
string. The OnCurrent handler checks the length of RecordSource, and exists
without doing anything if it's zero. The subform also has a procedure the
container form can call to restore the RecordSoruce property from the
variable, and the container calls that method of the subform in its own OnOpen
handler. That causes the subform's OnCurrent to fire for the first row, that
sets the value of the Id control on the container, and that causes the correct
related records to appear in the child second subform.