469,630 Members | 1,209 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,630 developers. It's quick & easy.

Adding records to a subform from a main form

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
0 1739

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Andante.in.Blue | last post: by
1 post views Thread by Richard Hollenbeck | last post: by
6 posts views Thread by 6thirty | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.