Solved On Subform2 within Subform1 : Criteria for a lookup Query (to refer to a control on Subform1) (1 Viewer)

alan2013

Registered User.
Local time
Today, 00:27
Joined
Mar 24, 2013
Messages
69
The scenario : I have a Subform1 set within a 'Main' Form. Within Subform1, I have a control (Field1_PK) and a Subform2. On Subform2, I have a combo that takes its data from a lookup Query. Within the Query, I want to be able to limit the records to ones that have a value set to that of the current Field1_PK value in Subform1.

In the Query, I have set the Criteria for Field1_FK (present in Subform2) to the following :

[Forms]![Main]![Subform1].[Form]![Field1_PK]

And that - in itself - seems to be working. The problem comes when, in Subform1, I navigate (simply using the built-in navigation button) to another record. The lookup doesn't update accordingly. Do I need to be creating some VBA code in the On Current Event, in order to force the lookup to update ?
TIA
 

Gasman

Enthusiastic Amateur
Local time
Today, 08:27
Joined
Sep 21, 2011
Messages
14,299
Need to requery the combo.
However you could just link the fields in Master/Child fields.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 15:27
Joined
May 7, 2009
Messages
19,243
of course you need to Requery your subform2 so that it updates it's Rowsource.
do it on the Current event of subform1.

Private Sub Form_Current()
Forms!Main!Subform.Form.Requery
End Sub

consider also using Link Master/Child Fields on subform2, therefore you can avoid using Criteria on the Query.
 

alan2013

Registered User.
Local time
Today, 00:27
Joined
Mar 24, 2013
Messages
69
The issue seems to have been resolved now, with the addition of the following on Subform2 :

Private Sub Form_Current()
Me.Field1.Requery
End Sub

Regarding linking Master & Child fields : Field1_FK on Subform2 was already linked to Field1_PK on Subform1.

Reading back over my initial post, I didn't describe it well.
In any case, thanks Gasman and arnelgp
 

Users who are viewing this thread

Top Bottom