views:

46

answers:

2

I have a form called Transaction Entry. I have a subform called Batches. I want to be able to enter a date in the Transaction Entry form, and then enter multiple items on the subform, but have it always update the date from Transaction Entry form.

Basically it would be like what I have drawn out below, and would update the date automatically from the parent from to the subform's date field for every record.![alt text][1]

+1  A: 

The easiest thing you can do (if you know the subform will never be used anywhere else) is to add a "BeforeInsert" event and then reference the parent form

Private Sub Form_BeforeInsert(Cancel As Integer)
    Me.myDate = Forms!parentformname.commonDate
End Sub

You could also reference the parent without mentioning the form's name

Private Sub Form_BeforeInsert(Cancel As Integer)
    Me.myDate = Me.Parent.commonDate
End Sub
CodeSlave
You do not need any code.
Remou
+2  A: 

There should be no need for any code at all. It is possible to use the Link Child & Link Master Fields properties of the subform control (note: the subform control, not the form contained) for just this purpose. You can refer to the name of a control, not just field names in the link properties:

Link Master Fields : SomeID, NameOfDateControl

Link Child Fields : SomeID, NameOfDateField

Child fields are populated with the contents of the master fields.

Remou
Ooooohhhh good trick +1.
CodeSlave
Any expression can be used for Link Master or Link Child. For instance, the easiest way to link a detail continuous form and a single detail form is to have the link of the detail subform be the PK of the current record of the list subform (e.g., DetailForm.Form!PKFieldName). This is one of the glories of Access subforms, and it seems a lot of people who pop up with issues on SO don't even understand basic master/child form/subform structures that work for master/child related tables (e.g., invoice/invoice detail).
David-W-Fenton