Adding Record to Subform

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi All
I have a form that contains a subform, the form contains a JobID that is
linked to the Subform. I was tring to added 10 records to the Subform from
the main form but always get an error.
The following code is what I was using, setting the focus to the first
record and then add a new record.
Forms!FrmChild2![Parent-3 subform].Form!child.SetFocus
DoCmd.GoToRecord , , acNext
Any Ideas
Thanks in advance
 
Each form has an ActiveControl.
You need to make the subform control the active one on the main form:
Me.FrmChild2.SetFocus

You can then set focus to the desired control in that subform, e.g.:
Me.FrmChild2.Form![Parent-3 subform].SetFocus

Then you can set focus to the control in the sub-subform:
Me.FrmChild2.Form![Parent-3 subform].Form!Text0.SetFocus

Alternatively you could AddNew to the RecordsetClone of the sub-subform,
like this:
Dim rs As DAO.Recordset
Set rs = Me.FrmChild2.Form![Parent-3 subform].Form.RecordsetClone
rs.AddNew
rs!Surame = "Smith"
rs!FirstName = "Sally"
'etc
rs.Update
Set rs = Nothing
 
Thanks

Allen Browne said:
Each form has an ActiveControl.
You need to make the subform control the active one on the main form:
Me.FrmChild2.SetFocus

You can then set focus to the desired control in that subform, e.g.:
Me.FrmChild2.Form![Parent-3 subform].SetFocus

Then you can set focus to the control in the sub-subform:
Me.FrmChild2.Form![Parent-3 subform].Form!Text0.SetFocus

Alternatively you could AddNew to the RecordsetClone of the sub-subform,
like this:
Dim rs As DAO.Recordset
Set rs = Me.FrmChild2.Form![Parent-3 subform].Form.RecordsetClone
rs.AddNew
rs!Surame = "Smith"
rs!FirstName = "Sally"
'etc
rs.Update
Set rs = Nothing

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Murray said:
Hi All
I have a form that contains a subform, the form contains a JobID that is
linked to the Subform. I was tring to added 10 records to the Subform from
the main form but always get an error.
The following code is what I was using, setting the focus to the first
record and then add a new record.
Forms!FrmChild2![Parent-3 subform].Form!child.SetFocus
DoCmd.GoToRecord , , acNext
Any Ideas
Thanks in advance
 
Back
Top