DoCmd Record New that only affects a SubForm

  • Thread starter Thread starter Eug7
  • Start date Start date
E

Eug7

How do I get a subform to trigger to a new record when I move from th
main form record? If I set up a DoCmd.NewRec on the subform on curren
the main as well as the subform are triggered to new record. If
specify in the DoCmd the subform name it errors with object not open
 
This will depend very much on exactly which event on the main form should be
recognized as meaning you have come from the subform and now want to have
the subform move to a new record..... as opposed to the event happening when
you've not been in the subform at all and you don't want the subform to move
to a new record.

Can you tell us more about your form's setup and what you're doing with it?
Especially focus on when you go into the subform and when you come back out
of it, and what you're doing just before and after those moves.
 
Let me try.

I open the main form. The main form contains a subform with th
parent/child set to the key field. Let's say when I open the main for
I'm on record number 1. When I move to record number 2 I would like th
subform to be triggered to record new. The subform is not for dat
entry necessarily and that's why I don't set the subform property t
data entry. As previously stated both the main & sub move to new recor
if I use the on_current event from the main or subform to trigger th
DoCmd.RecordNew
 
OK - you could use the main form's Current event to do something like this.
Try this (untested) code:

Private Sub Form_Current()
If Me.SubForm.Form.NewRecord = False Then _
Me.SubForm.Form.Recordset.AddNew
End Sub

Replace SubForm with the actual name of the subform control (the control
that holds the actual subform) on the main form. This code should cause the
subform to move to a new record unless it's already on a new record.
 
Back
Top