Adding Record to Subform

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
 
A

Allen Browne

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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top