Subform Data Entry question

S

Stacey

I've been struggling with this for some time. I have a Date field on the
main form, I am trying to get the date field to copy itself to a datasheet
date field with mutiple rows. Each row should have the same date field
displayed in the parent form. Any help on this is greatly appreciated.
Thanks in advance!
 
T

tina

it's not clear what you're doing. are you adding records to the subform, and
want the date to populate the field in each record, as you add it? or is the
subform *already populated* with records, and you want the date field of all
the records edited to match the date on the main form? more details, please.

hth
 
S

Stacey

the second part of your response........, the subform has records already
populated with the exception of the date field, it is blank....I would like
the date field populated from whatever date is in the master form date field .
 
S

Stacey

This is wat I have so far, I put the code in main form: However it only
populates the first record in the Subform....how can I get it to populate the
other records?

Private Sub Form_AfterUpdate()
Me.Termed_subform.Term_Date = Me.Term_Date
End Sub
 
J

John W. Vinson

This is wat I have so far, I put the code in main form: However it only
populates the first record in the Subform....how can I get it to populate the
other records?

Private Sub Form_AfterUpdate()
Me.Termed_subform.Term_Date = Me.Term_Date
End Sub

You're making a very common mistake: assuming that the data you see in a
subform is stored in the subform. It isn't!

The subform is JUST A WINDOW onto the data, which is stored in the Table, and
only in the Table.

You must run an Update query updating the desired records in the table. Since
I don't know how your form is set up, what its master/child link fields, etc.
are, I can't give the exact code, but it would be an update query updating the
subform's source table using the ID in the master link field as a criterion to
update only the currently displayed records.

John W. Vinson [MVP]
 
J

John W. Vinson

John, can you please give me an example of what you mean?

Sure. Since I have no idea what your table or fieldnames might be, you'll need
to adapt this; but you can create a new Query in the query design window to
update the subform's table. Use a criterion on the foreign key field (the one
in the Subform's "Child Link Field" property) like

=[Forms]![YourFormName]![txtIDfield]

where txtIDfield is the name of a textbox or other control on the form which
contains the master link field.

Change the query to an Update query, and put

=Forms![yourformname]![Term_date]

on the Update To line under the field that you want updated.

One serious question: WHY? It looks like you're storing this data redundantly
in two different tables. Does the child table really need this date stored, if
it's already stored in the mainform's table?

John W. Vinson [MVP]
 
S

Stacey

John, I gave your comment some thought and you are absolutly right....what
was I thinking? I would be storing the same data in two tables (going
against the Access Mantra)! Thanks for stearing me in the right direction!

John W. Vinson said:
John, can you please give me an example of what you mean?

Sure. Since I have no idea what your table or fieldnames might be, you'll need
to adapt this; but you can create a new Query in the query design window to
update the subform's table. Use a criterion on the foreign key field (the one
in the Subform's "Child Link Field" property) like

=[Forms]![YourFormName]![txtIDfield]

where txtIDfield is the name of a textbox or other control on the form which
contains the master link field.

Change the query to an Update query, and put

=Forms![yourformname]![Term_date]

on the Update To line under the field that you want updated.

One serious question: WHY? It looks like you're storing this data redundantly
in two different tables. Does the child table really need this date stored, if
it's already stored in the mainform's table?

John W. Vinson [MVP]
 
Top