By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,688 Members | 1,888 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,688 IT Pros & Developers. It's quick & easy.

Adding records to a subform from a main form

P: n/a
Hi all,.

I have a small issue I would like to resolve with VBA. I have a form
which
it's fields are bound to a table. Within that form is a subform which
is a
subtable.

Tables relationship is a one to many from the main table to the sub
table.

On the main form I have a "Add Record" button which creates a new
record in
the main table.

What I want to do is put a statement in that Add Record button, on
click
event that will automatically add 20 records to the subtable where the
first
field in the sub form is numberd 1-20.
Obviously I can go to the subform and put in a button that will do
that
using this code(Lane is the first field in the subtable/form):

Me.Lane = 1
DoCmd.GoToRecord , , acNewRec
Me.Lane = 2
DoCmd.GoToRecord , , acNewRec
Me.Lane = 3
DoCmd.GoToRecord , , acNewRec
Me.Lane = 4
DoCmd.GoToRecord , , acNewRec
Me.Lane = 5
DoCmd.GoToRecord , , acNewRec
Me.Lane = 6
DoCmd.GoToRecord , , acNewRec
Me.Lane = 7
DoCmd.GoToRecord , , acNewRec
Me.Lane = 8
DoCmd.GoToRecord , , acNewRec
Me.Lane = 9
DoCmd.GoToRecord , , acNewRec
Me.Lane = 10
DoCmd.GoToRecord , , acNewRec
Me.Lane = 11
DoCmd.GoToRecord , , acNewRec
Me.Lane = 12
DoCmd.GoToRecord , , acNewRec
Me.Lane = 13
DoCmd.GoToRecord , , acNewRec
Me.Lane = 14
DoCmd.GoToRecord , , acNewRec
Me.Lane = 15
DoCmd.GoToRecord , , acNewRec
Me.Lane = 16
DoCmd.GoToRecord , , acNewRec
Me.Lane = 17
DoCmd.GoToRecord , , acNewRec
Me.Lane = 18
DoCmd.GoToRecord , , acNewRec
Me.Lane = 19
DoCmd.GoToRecord , , acNewRec
Me.Lane = 20
But I would prefer my users not have to push 2 buttons for a new
record.
What code would I use to add to the main form's "Add Record" button to
achive
the same results as adding a button and the code directly to the
subform?

Thanks

Sep 21 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.