Populating Fields On Subform

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I have a subform that is opened off a main form with a button. What I would
like to have happen is for four of the fields to link back to the main form
and be populated with their values. The subform is a billing form that is
used by several other main forms as well so it needs to recognize the other
forms are in use.

I would like to put code in that tells the subform to recognize the fields
but each time I put the code in I get an empty field. If I put the main form
name in each field's default value with the full form path it works, but for
only one form.

The code I put in was:
stLinkCriteria = "[HouseRollNumber]=" & "'" & Me![HouseRollNumber] & "'"

Can someone let me know what I am doing wrong.

Thanks
IEJ
 
IEJ,

I think you are not really referring to a subform. A subform doesn't
get opened. A subform is embedded in another form. It sounds like what
you are referring to as a subform is actualy a stand-alone form in its
own right.... am I right?

I am not sure what stLinkCriteria refers to, but maybe it would help if
you could give some more specific information about how you are going
about things.

In the meantime, it is probably easier to use data from tables rather
than try and reference the data from a control on another form. There
would be two approaches to this. First, if the second form is being
opened at a record related to the current record on the first form, then
it is likely that the data you want shown on the second form is in a
table which is related to the table that the second form is based on.
Hope that makes sense. Therefore, it is likely you will be able to make
a query that includes the table where this related data is, and base the
second form on this query instead of its present record source. That
way, you can represent the data directly on the form in controls bound
to these fields in the query. Another approach, if the first is not
applicable, is to use DLookup() function in the control source of
unbound controls on the second form, to retreive and display the
required data.
 
You are quite right, sorry I did call it a subform but you are right I have a
button and it is a form of its own. I have four fields that are fields that
link the payroll together so what I want to achieve is that when the second
form opens, the four fields that have been filled in on the first form are
prepopulated on the second form when it is opened. The billing categories
form is used for a couple of other places so I want it to populate the values
from the form that it is opening from. I think if I use the Dlook up I have
to put in a specific form name.

Thanks,
IEJ


Steve Schapel said:
IEJ,

I think you are not really referring to a subform. A subform doesn't
get opened. A subform is embedded in another form. It sounds like what
you are referring to as a subform is actualy a stand-alone form in its
own right.... am I right?

I am not sure what stLinkCriteria refers to, but maybe it would help if
you could give some more specific information about how you are going
about things.

In the meantime, it is probably easier to use data from tables rather
than try and reference the data from a control on another form. There
would be two approaches to this. First, if the second form is being
opened at a record related to the current record on the first form, then
it is likely that the data you want shown on the second form is in a
table which is related to the table that the second form is based on.
Hope that makes sense. Therefore, it is likely you will be able to make
a query that includes the table where this related data is, and base the
second form on this query instead of its present record source. That
way, you can represent the data directly on the form in controls bound
to these fields in the query. Another approach, if the first is not
applicable, is to use DLookup() function in the control source of
unbound controls on the second form, to retreive and display the
required data.

--
Steve Schapel, Microsoft Access MVP


Hello,

I have a subform that is opened off a main form with a button. What I would
like to have happen is for four of the fields to link back to the main form
and be populated with their values. The subform is a billing form that is
used by several other main forms as well so it needs to recognize the other
forms are in use.

I would like to put code in that tells the subform to recognize the fields
but each time I put the code in I get an empty field. If I put the main form
name in each field's default value with the full form path it works, but for
only one form.

The code I put in was:
stLinkCriteria = "[HouseRollNumber]=" & "'" & Me![HouseRollNumber] & "'"

Can someone let me know what I am doing wrong.

Thanks
IEJ
 
IEJ,

Thanks for the further explanation.

When you enter the data into the first form, this data must be going
into a table somewhere, right? What I meant was, instead of trying to
reference the values from the controls on the first form to the controls
on the second form, that you get them from the table instead. Two
possible methods... include the table in the query that the second form
is based on, or use DLookup() to reference the values from the table.
Thus it doesn't matter which form is opening the second form. Is there
any reason why you can't do it this way?
 
Back
Top