How to bind a control of main form to subform (1 Viewer)

datefruit

New member
Local time
Today, 17:45
Joined
Dec 1, 2012
Messages
6
How to bind a control of main form to subform field

Explanation:
In Access 2010 I've made a Main form1 with a linked subform1 (the subform1 linked using “Link Child Fields, Link Master Fields”).
In form1 I’m able to select records from a query and display related records in subform1.

My question:
Is it possible to bind a control (Text Box) of form1 to “subform1 field” to be able not only to display*, but also to enter and update values for the records selected in subform1.
Or I can only bind control to fields in the “Record Source” of the Form on which this control (Text Box) resides. In this case I'll need a help finding a solution of my problem:

I'm making a foreign language dictionary where 1 record (selected in form1) has several related records (displayed in subform1) and I need to be able to view and edit this related records enlarged in Text Boxes of main form1 (especially "Memo" fields with several lines of text).

* - I'm able to display subform1 value in form1 control by writing Control Source:
Code:
=[subForm1].[Form]![fieldName1]
But in this case I got an alert (error) on the Access status bar:
"Control can't be edited; it's bound to the expression ..."
 
Last edited:

llkhoutx

Registered User.
Local time
Today, 10:45
Joined
Feb 26, 2001
Messages
4,018
Refetnce the subform control as the control source of the related form control
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 11:45
Joined
Feb 19, 2002
Messages
42,970
Shift-F2 in any control will open a zoom box that will allow editing. No coding is required.
 

datefruit

New member
Local time
Today, 17:45
Joined
Dec 1, 2012
Messages
6
Attempt #1
OK. I need to “Reference the subform control as the control source of the related form control”.
To refer to a control on a subform, I've tried to use the following Control Source:
Code:
=Forms![mainFormName]![subformName].Form![subformControlName]
Result: It didn't work.
The mainFormControl (Text Box) displays the subformControl data, but again while trying to edit this data in I'm getting an alert on the Access status bar: "Control can't be edited; it's bound to the expression ..."
Maybe that's because I need "to bind" and not only "to refer" subform Control?
 
Last edited:

nanscombe

Registered User.
Local time
Today, 15:45
Joined
Nov 12, 2011
Messages
1,082
An unbound control on the main form and coding like the following?

Code:
Private Sub mainFormControl_AfterUpdate()
  Me.[subformName].Form![subformControl Name] = Me.mainFormControl
End Sub

Private Sub mainForm_Current()
  Me.mainFormControl = Me.[subformName].Form![subformControl Name]
End Sub
 

datefruit

New member
Local time
Today, 17:45
Joined
Dec 1, 2012
Messages
6
Attempt #2
I've unbounded mainFormControl and coded like the following:
Code:
Private Sub mainFormControl_AfterUpdate()
  Me.[subformName].Form![subformControl Name] = Me.mainFormControl
End Sub
Private Sub mainForm_Current()
  Me.mainFormControl = Me.[subformName].Form![subformControl Name]
End Sub
Result: code by "nanscombe" partially worked for me.
Now I'm able to update subformControl by changing data in mainFormControl, but when I choose the different record in subForm, the mainFormControl remains unchanged.
I need to be able to update mainFormControl as well.
 

nanscombe

Registered User.
Local time
Today, 15:45
Joined
Nov 12, 2011
Messages
1,082
Sorry, it may be better to use subForm_Current(), ie on the sub form, to push the data to the mainForm instead of pulling it using form_Current() on the main form
 

datefruit

New member
Local time
Today, 17:45
Joined
Dec 1, 2012
Messages
6
Attempt #2.2
I've followed the advice by "nanscombe" and added to subForm the following code:
Code:
Private Sub Form_Current()
Me.Parent.[mainFormControlName] = Me.[subformControlName]
End Sub
Result: Everything seems to work. Thanks a lot.
Now I'm going to perform a test run of this code in different situations.
 
Last edited:

Users who are viewing this thread

Top Bottom