Update from form to subforms 
Author Message
 Update from form to subforms

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



Mon, 29 Aug 2005 10:21:27 GMT  
 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



Mon, 29 Aug 2005 21:15:45 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Updating a form containing subforms

2. Forms, subforms and automatic update of the underlying table

3. Forms - subforms - after update event

4. Forms/SubForms & Data/Update Event sequence

5. Update Subforms records from ComboBox on Main Form

6. Update forms/subforms

7. Subforms not (always) updating with the main form

8. 2 subforms on a main form - both subforms not refreshing

9. Subforms not updating after cascade update

10. Searhing forms/subforms/sub-subforms.


 
Powered by phpBB® Forum Software © phpBB Group