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 pa开发者_运维百科rent from to the subform's date field for every record.![alt text][1]
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.
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
精彩评论