Open forms AND SUBFORMS on new record

K

Kurt

I have a main form with several linked subforms.

I would always like the main form to open on a new
record, but still allow the user to go edit other
records. So I put some code in the Form_Open event of the
main form. The main form opens on a new record, but the
*subforms* still open on the first record.

Do I need to put "DoCmd.GoToRecord , , acNewRec" in the
Open Form event for all the subforms, too? Or is there an
easier way?

This is the code for the main form:

###

Private Sub Form_Open(Cancel As Integer)
DoCmd.GoToRecord , , acNewRec
End Sub

###

Thanks.

Kurt
 
R

Rob Oldfield

If your subforms are linked to your main form then that would be the default
behaviour. How are you doing the linking?
 
K

Kurt

If your subforms are linked to your main form then that
would be the default behaviour. How are you doing the
linking?

The subforms are linked to the main form using the
primary key for both the child and master fields.

This is why I would have assumed that, if the main form
opens on a new record, the subforms would as well.
 
R

Rob Oldfield

So if you just move between different records on the main form... do the
subforms remain synchronised? Do you have fields on both the main and
subform that display the linking fields? (you don't really need them, but
they might be useful to see what is going on)

If you create a query containing fields from both main and (one of the)
subtables, linking that same field, does it work?
 
R

Rob Oldfield

Kurt said:
The subforms are linked to the main form using the
primary key for both the child and master fields.

This is why I would have assumed that, if the main form
opens on a new record, the subforms would as well.

Hopefully you don't mean the pk of the child table. You do have a foreign
key field in that table? If you ensure that both of your forms show the
linking field, then what do they both show when you go to a new record?
 

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