
Update from form to subforms
Are you just trying to set the Recordid for new subform records or are there
already records related to the record in frmLocation? If you are just trying
to set RecordID on new subform records make sure that you have set the
LinkMasterFields and LinkChildFields to 'Recordid' and that you have
established a relationship with referential integrity between the two
tables, then Access will take care of assigning the Recordid from the main
form to each new subform record.
Otherwise, in the BeforeInsert event of the subform you can set it by the
following:
me.Recordid = me.parent.recordid
Also, in frmBoreHoleLoad, since you passed the Recordid in using OpenArgs,
you don't have to refer back to frmLocation (IOW do one or the other).
Private Sub Form_frmBoreHoleLoad()
if len(me.openargs & "") >0 then
me.recordid.defaultvalue=me.openargs
endif
'Or
' BOREHOLEDATASOURCE_RecordID.DefaultValue = Val(Form_frmLocation.RecordID)
End Sub
--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.
Quote:
> Hi all,
> I have two forms - frmLocation and frmData.
> frmData is a tabbed form constituting of fields from
> tables that are either 1-1 or 1-many relationship.
> the 1-many are in the form of subforms.
> I have an autonumber unique field in frmLocation which I
> am updating in 1-1 tabs of frmData by the following code
> //This is a combo box at the end of frmLocation which on
> choosing different values opens different forms and I want
> to pass the RecordID in these child forms.
> Private Sub frmLocationCombobox_AfterUpdate()
> Select Case DATATYPE_DataTypeID
> Case 1
> DoCmd.OpenForm "frmBoreHole", , , , , , RecordID
> Case 2
> DoCmd.OpenForm "frmWaterQuality", , , , , ,
> RecordID
> Case 3
> DoCmd.OpenForm "frmRadon", , , , , , RecordID
> End Select
> End Sub
> //BOREHOLEDATASOURCE_RecordID is the control for the
> recordID field in the frmData
> Private Sub Form_frmBoreHoleLoad()
> BOREHOLEDATASOURCE_RecordID.DefaultValue = Val
> (Form_frmLocation.RecordID)
> End Sub
> I have no problems for the 1-1 forms using the above code.
> Can somebody please help me how to go about updating
> RecordID in the subforms (1-Many tabs) in frmData.
> Any help appreciated.
> Sincerely,
> Dan