Go Back   Access World Forums > Microsoft Access Discussion > Forms

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 12-01-2012, 10:44 AM   #1
datefruit
Newly Registered User
 
Join Date: Dec 2012
Location: Belarus
Posts: 6
Thanks: 5
Thanked 1 Time in 1 Post
datefruit is on a distinguished road
Question 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 by datefruit; 12-02-2012 at 01:28 AM.
datefruit is offline   Reply With Quote
Old 12-01-2012, 02:16 PM   #2
llkhoutx
Newly Registered User
 
Join Date: Feb 2001
Location: Houston,Texas USA
Posts: 4,018
Thanks: 6
Thanked 106 Times in 104 Posts
llkhoutx is on a distinguished road
Re: How to bind a control of main form to subform

Refetnce the subform control as the control source of the related form control
__________________
Get the job done right, rather than do the right job.
Do it fast or do it right. Teach a man a fish . . .
If it ain't broke, don't fix it.
Note that I don't open posted databases, period.
llkhoutx is offline   Reply With Quote
Old 12-01-2012, 02:38 PM   #3
Pat Hartman
Super Moderator
 
Join Date: Feb 2002
Location: Stratford,Ct USA
Posts: 27,555
Thanks: 13
Thanked 1,453 Times in 1,385 Posts
Pat Hartman is a name known to all Pat Hartman is a name known to all Pat Hartman is a name known to all Pat Hartman is a name known to all Pat Hartman is a name known to all Pat Hartman is a name known to all
Re: How to bind a control of main form to subform

Shift-F2 in any control will open a zoom box that will allow editing. No coding is required.

__________________
Bridge Players Still Know All the Tricks
Pat Hartman is offline   Reply With Quote
Old 12-02-2012, 01:27 AM   #4
datefruit
Newly Registered User
 
Join Date: Dec 2012
Location: Belarus
Posts: 6
Thanks: 5
Thanked 1 Time in 1 Post
datefruit is on a distinguished road
Question Re: How to bind a control of main form to subform

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 by datefruit; 12-02-2012 at 01:34 AM.
datefruit is offline   Reply With Quote
Old 12-02-2012, 01:32 AM   #5
nanscombe
Newly Registered User
 
nanscombe's Avatar
 
Join Date: Nov 2011
Location: Kent, UK.
Posts: 1,082
Thanks: 0
Thanked 256 Times in 249 Posts
nanscombe will become famous soon enough
Re: How to bind a control of main form to subform

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
__________________
Nigel
Ex Tactical Systems developer
nanscombe is offline   Reply With Quote
Old 12-02-2012, 03:20 AM   #6
datefruit
Newly Registered User
 
Join Date: Dec 2012
Location: Belarus
Posts: 6
Thanks: 5
Thanked 1 Time in 1 Post
datefruit is on a distinguished road
Question Re: How to bind a control of main form to subform

Attempt #2
I've unbounded mainFormControl and coded like the following:
Quote:
Originally Posted by nanscombe View Post
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.
datefruit is offline   Reply With Quote
Old 12-02-2012, 03:29 AM   #7
nanscombe
Newly Registered User
 
nanscombe's Avatar
 
Join Date: Nov 2011
Location: Kent, UK.
Posts: 1,082
Thanks: 0
Thanked 256 Times in 249 Posts
nanscombe will become famous soon enough
Re: How to bind a control of main form to subform

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

__________________
Nigel
Ex Tactical Systems developer
nanscombe is offline   Reply With Quote
The Following User Says Thank You to nanscombe For This Useful Post:
datefruit (12-02-2012)
Old 12-02-2012, 03:49 AM   #8
datefruit
Newly Registered User
 
Join Date: Dec 2012
Location: Belarus
Posts: 6
Thanks: 5
Thanked 1 Time in 1 Post
datefruit is on a distinguished road
Smile Re: How to bind a control of main form to subform

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 by datefruit; 12-02-2012 at 05:14 AM.
datefruit is offline   Reply With Quote
The Following User Says Thank You to datefruit For This Useful Post:
vperep (03-05-2014)
Old 03-05-2014, 10:56 AM   #9
vperep
Newly Registered User
 
Join Date: Mar 2014
Posts: 1
Thanks: 1
Thanked 0 Times in 0 Posts
vperep is on a distinguished road
Re: How to bind a control of main form to subform

Grat advize! It works!

vperep is offline   Reply With Quote
Reply

Tags
bind , control , form , link , subform

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How To Assign A SubForm Value To A Control In Main Form ? cheer Forms 2 12-23-2011 07:26 PM
Bind Save Record control to update query in subform MatthewJapp General 0 02-02-2011 05:32 AM
Control for a subform on the main form fenhow Forms 5 08-01-2007 01:19 PM
Get subform's control in the main form. dudezzz Forms 1 02-21-2005 01:05 PM
pop control in subform from main form TLJ Forms 5 08-25-2003 06:48 AM




All times are GMT -8. The time now is 09:28 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World