Binding Controls to a Subform

J

Joshua Beel

How do I bind what is displayed in the controls of my form to what is
selected within the subform?
 
K

Ken Sheridan

From your brief description I'm not quite sure what you have in mind, but if
you mean you want to reference a control in a subform as the ControlSource
property of a control in the parent form then you do so via the Form property
of the subform control (that's the control in the parent form which houses
the subform), so the syntax is:

=[SubformControlName].[Form].[NameOfControlOnSubform]

Bear in mind that if the control on a subform is a combo box its value might
not necessarily be the value you see in it, but a hidden column, e.g. a
numeric ID number corresponding to a visible text value. If so then you
would need to add a reference to the relevant column by means of the combo
box's Column property. This is zero-based so referencing the second column
would be Column(1), the third column Column(2) and so on.

You use the term 'bind' but the control in the parent form in the above case
would of course be an unbound control, so if you have something else in mind
post back with a more detailed description of your requirement.

Ken Sheridan
Stafford, England
 
J

Joshua Beel

Thank you for your reply Ken.

I think I need to better specify the issue. I would like to create a form
that is similar in functionality to the Split form, in which when you select
a record from within the table in the split form, it displays all information
within the controls of the main form.

Ken Sheridan said:
From your brief description I'm not quite sure what you have in mind, but if
you mean you want to reference a control in a subform as the ControlSource
property of a control in the parent form then you do so via the Form property
of the subform control (that's the control in the parent form which houses
the subform), so the syntax is:

=[SubformControlName].[Form].[NameOfControlOnSubform]

Bear in mind that if the control on a subform is a combo box its value might
not necessarily be the value you see in it, but a hidden column, e.g. a
numeric ID number corresponding to a visible text value. If so then you
would need to add a reference to the relevant column by means of the combo
box's Column property. This is zero-based so referencing the second column
would be Column(1), the third column Column(2) and so on.

You use the term 'bind' but the control in the parent form in the above case
would of course be an unbound control, so if you have something else in mind
post back with a more detailed description of your requirement.

Ken Sheridan
Stafford, England

Joshua Beel said:
How do I bind what is displayed in the controls of my form to what is
selected within the subform?
 
P

Pete D.

Hi,
Have you looked at the Microsoft sample database? Might help you get
started. Pete D.
http://www.microsoft.com/downloads/...72-8DBE-422B-8676-C632D66C529C&displaylang=en

Joshua Beel said:
Thank you for your reply Ken.

I think I need to better specify the issue. I would like to create a form
that is similar in functionality to the Split form, in which when you
select
a record from within the table in the split form, it displays all
information
within the controls of the main form.

Ken Sheridan said:
From your brief description I'm not quite sure what you have in mind, but
if
you mean you want to reference a control in a subform as the
ControlSource
property of a control in the parent form then you do so via the Form
property
of the subform control (that's the control in the parent form which
houses
the subform), so the syntax is:

=[SubformControlName].[Form].[NameOfControlOnSubform]

Bear in mind that if the control on a subform is a combo box its value
might
not necessarily be the value you see in it, but a hidden column, e.g. a
numeric ID number corresponding to a visible text value. If so then you
would need to add a reference to the relevant column by means of the
combo
box's Column property. This is zero-based so referencing the second
column
would be Column(1), the third column Column(2) and so on.

You use the term 'bind' but the control in the parent form in the above
case
would of course be an unbound control, so if you have something else in
mind
post back with a more detailed description of your requirement.

Ken Sheridan
Stafford, England

Joshua Beel said:
How do I bind what is displayed in the controls of my form to what is
selected within the subform?
 
K

Ken Sheridan

Lets assume the primary key of the table in question is CustomerID. Both the
main form and subform should be bound to the table. Then put code along
these lines in the Current event procedure of the subform:

Dim rst As Object

Set rst = Me.Parent.Recordset.Clone

rst.FindFirst "CustomerID = " & Nz(Me.CustomerID,0)
If Not rst.NoMatch Then
Me.Parent.Bookmark = rst.Bookmark
Else
DoCmd.GoToRecord acForm, Me.Parent.Name, acNewRec
End If

This assumes CustomerID is a number data type. If it were text you'd wrap
the value in quotes characters:

rst.FindFirst "CustomerID = """ & Me.CustomerID & """"

Ken Sheridan
Stafford, England

Joshua Beel said:
Thank you for your reply Ken.

I think I need to better specify the issue. I would like to create a form
that is similar in functionality to the Split form, in which when you select
a record from within the table in the split form, it displays all information
within the controls of the main form.

Ken Sheridan said:
From your brief description I'm not quite sure what you have in mind, but if
you mean you want to reference a control in a subform as the ControlSource
property of a control in the parent form then you do so via the Form property
of the subform control (that's the control in the parent form which houses
the subform), so the syntax is:

=[SubformControlName].[Form].[NameOfControlOnSubform]

Bear in mind that if the control on a subform is a combo box its value might
not necessarily be the value you see in it, but a hidden column, e.g. a
numeric ID number corresponding to a visible text value. If so then you
would need to add a reference to the relevant column by means of the combo
box's Column property. This is zero-based so referencing the second column
would be Column(1), the third column Column(2) and so on.

You use the term 'bind' but the control in the parent form in the above case
would of course be an unbound control, so if you have something else in mind
post back with a more detailed description of your requirement.

Ken Sheridan
Stafford, England

Joshua Beel said:
How do I bind what is displayed in the controls of my form to what is
selected within the subform?
 
Top