Refer to a field on a subform

G

Glenn Suggs

I'm trying to load a text box on a subform with the information in a text box
on the main form. I can't seem to get it to work as I get the error message
that the subform can't be found.

I've tried using these pieces of code but they don't work.
Me.sbfSubform.Form!txtTextBox = Me.txtTextBox
and
[Forms]![frmMainForm]![sbfSubForm]!txtTextBox = me.txtTextBox

Can someone help please? Thanks in advance.
 
J

Jeanette Cunningham

Glenn,
from the subform the code looks like this - use it in the control source of
the text box on the subform

=Parent.txtTextBox

Jeanette Cunningham
 
G

Glenn Suggs

Jeanette,
I tried what you suggested before posting my question but I was looking to
bind the textbox on the subform to a field in a table and allow the user to
type in the data on the main form. Then I was trying to have code update the
subform control (and therefore also the table). It seems there would be a
way to do that but I can go back to your suggested method if need be.
Thanks again,
--
Glenn


Jeanette Cunningham said:
Glenn,
from the subform the code looks like this - use it in the control source of
the text box on the subform

=Parent.txtTextBox

Jeanette Cunningham

Glenn Suggs said:
I'm trying to load a text box on a subform with the information in a text
box
on the main form. I can't seem to get it to work as I get the error
message
that the subform can't be found.

I've tried using these pieces of code but they don't work.
Me.sbfSubform.Form!txtTextBox = Me.txtTextBox
and
[Forms]![frmMainForm]![sbfSubForm]!txtTextBox = me.txtTextBox

Can someone help please? Thanks in advance.
 
J

Jeanette Cunningham

Glenn,
the usual way is to make the textbox on the subform bound to a field in the
subform's recordsource. If you want users to type in a value in the subform,
they can do it in the subform or you could open a new form.
Create a form with one field, the textbox can be unbound. Open this form in
acDialog mode either from a button or when the main form opens.
When the user clicks the close button on this new form, code updates the
value into the subform.
Something like this:

Private Sub CloseBtn_Click()
Forms!TheMainForm!TheSubformControlName!txtTextBox = Me.NewFormControlName
Do.Cmd Close acForm, Me.Name
End Sub

Jeanette Cunningham

Glenn Suggs said:
Jeanette,
I tried what you suggested before posting my question but I was looking to
bind the textbox on the subform to a field in a table and allow the user
to
type in the data on the main form. Then I was trying to have code update
the
subform control (and therefore also the table). It seems there would be a
way to do that but I can go back to your suggested method if need be.
Thanks again,
--
Glenn


Jeanette Cunningham said:
Glenn,
from the subform the code looks like this - use it in the control source
of
the text box on the subform

=Parent.txtTextBox

Jeanette Cunningham

Glenn Suggs said:
I'm trying to load a text box on a subform with the information in a
text
box
on the main form. I can't seem to get it to work as I get the error
message
that the subform can't be found.

I've tried using these pieces of code but they don't work.
Me.sbfSubform.Form!txtTextBox = Me.txtTextBox
and
[Forms]![frmMainForm]![sbfSubForm]!txtTextBox = me.txtTextBox

Can someone help please? Thanks in advance.
 
G

Glenn Suggs

Jeanette,
Thank you very much for your help. The process works exactly like i wanted
it to now. The part I needed was:
Forms!TheMainForm!TheSubformControlName!txtTextBox = Me.txtBox
I often get confused about when to use the name of the subform and when to
use the subform "Control" name. If there's a list of rules for when to use
what, I'd like to know.
Thanks again,
--
Glenn


Jeanette Cunningham said:
Glenn,
the usual way is to make the textbox on the subform bound to a field in the
subform's recordsource. If you want users to type in a value in the subform,
they can do it in the subform or you could open a new form.
Create a form with one field, the textbox can be unbound. Open this form in
acDialog mode either from a button or when the main form opens.
When the user clicks the close button on this new form, code updates the
value into the subform.
Something like this:

Private Sub CloseBtn_Click()
Forms!TheMainForm!TheSubformControlName!txtTextBox = Me.NewFormControlName
Do.Cmd Close acForm, Me.Name
End Sub

Jeanette Cunningham

Glenn Suggs said:
Jeanette,
I tried what you suggested before posting my question but I was looking to
bind the textbox on the subform to a field in a table and allow the user
to
type in the data on the main form. Then I was trying to have code update
the
subform control (and therefore also the table). It seems there would be a
way to do that but I can go back to your suggested method if need be.
Thanks again,
--
Glenn


Jeanette Cunningham said:
Glenn,
from the subform the code looks like this - use it in the control source
of
the text box on the subform

=Parent.txtTextBox

Jeanette Cunningham

I'm trying to load a text box on a subform with the information in a
text
box
on the main form. I can't seem to get it to work as I get the error
message
that the subform can't be found.

I've tried using these pieces of code but they don't work.
Me.sbfSubform.Form!txtTextBox = Me.txtTextBox
and
[Forms]![frmMainForm]![sbfSubForm]!txtTextBox = me.txtTextBox

Can someone help please? Thanks in advance.
 
J

Jeanette Cunningham

There is a list like that on The Access Web.
Here is the url:
http://www.mvps.org/access/forms/frm0031.htm

Jeanette Cunningham


Glenn Suggs said:
Jeanette,
Thank you very much for your help. The process works exactly like i
wanted
it to now. The part I needed was:
Forms!TheMainForm!TheSubformControlName!txtTextBox = Me.txtBox
I often get confused about when to use the name of the subform and when to
use the subform "Control" name. If there's a list of rules for when to
use
what, I'd like to know.
Thanks again,
--
Glenn


Jeanette Cunningham said:
Glenn,
the usual way is to make the textbox on the subform bound to a field in
the
subform's recordsource. If you want users to type in a value in the
subform,
they can do it in the subform or you could open a new form.
Create a form with one field, the textbox can be unbound. Open this form
in
acDialog mode either from a button or when the main form opens.
When the user clicks the close button on this new form, code updates the
value into the subform.
Something like this:

Private Sub CloseBtn_Click()
Forms!TheMainForm!TheSubformControlName!txtTextBox =
Me.NewFormControlName
Do.Cmd Close acForm, Me.Name
End Sub

Jeanette Cunningham

Glenn Suggs said:
Jeanette,
I tried what you suggested before posting my question but I was looking
to
bind the textbox on the subform to a field in a table and allow the
user
to
type in the data on the main form. Then I was trying to have code
update
the
subform control (and therefore also the table). It seems there would
be a
way to do that but I can go back to your suggested method if need be.
Thanks again,
--
Glenn


:

Glenn,
from the subform the code looks like this - use it in the control
source
of
the text box on the subform

=Parent.txtTextBox

Jeanette Cunningham

I'm trying to load a text box on a subform with the information in a
text
box
on the main form. I can't seem to get it to work as I get the error
message
that the subform can't be found.

I've tried using these pieces of code but they don't work.
Me.sbfSubform.Form!txtTextBox = Me.txtTextBox
and
[Forms]![frmMainForm]![sbfSubForm]!txtTextBox = me.txtTextBox

Can someone help please? Thanks in advance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top