linking field from main form to sub form (1 Viewer)

Stoic

Registered User.
Local time
Today, 10:58
Joined
May 15, 2013
Messages
24
Hi,
I have an entry form with a field(combo box) called cboGetCode. I also have a sub form (continuous form) with number of fields, also an entry form. Now, I have added a code behind the cboGetCode AfterUpdate event to populate the result to relevant fields in the main form.
PHP:
Me.lngSCode = DLookup("[lngSchoolCode]", "[qrReadingFirstSchools]", "[lngSchoolCode]='" & Me.cboGetCode & "'")

This is working very well.
Now, what I would like to do is get code as shown in the cboGetCode field to my sub form lngSCode field.

Any help?
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 06:58
Joined
Feb 19, 2002
Messages
42,981
DLookup() is a poor solution for something like this. The best practice is to include the lookup table/query in the RecordSource query for the form/report. Then you can join to the main table and select columns from each. When the value in the combo changes, the value of the lookup field will also automagically change. When you do this though, it is best to set the locked property of the lookup fields to yes to prevent accidental updates.
 

Users who are viewing this thread

Top Bottom