add one entry to make several records

  • Thread starter Thread starter Sue
  • Start date Start date
S

Sue

Hi,
Is it possible to put a number in a form and get this to
make new records in the table the form is based on. I.e.
If the form has a field called Male and I enter 8, 8 new
records will appear in the table with Male written in
them?
I've heard loops and append queries could be used but I
can't get them going?
I would love some help!
thanks
Sue
 
yes, on the after_update of the unbound control male

dim rs as dao.recordset
dim i as integer
set rs = me.recordsetclone
for i=1 to me.Controls("Male").Value
rs.addnew
rs.fields("Gender")="Male"
rs.update
next
rs.bookmark=me.bookmark
me.requery
me.bookmark=rs.bookmark

hth
Pieter
 
Hi,
Is it possible to put a number in a form and get this to
make new records in the table the form is based on. I.e.
If the form has a field called Male and I enter 8, 8 new
records will appear in the table with Male written in
them?
I've heard loops and append queries could be used but I
can't get them going?
I would love some help!
thanks
Sue

As a rule, this would not be all that good an idea: what are you going
to do with eight identical (or identical but for the autonumber)
records?

However, you can use either VBA as suggested elsethread or a Query to
create them; for the query you'll need a handy little table named NUM
with one long-integer field N. Fill this table with values from 0 to
the most records you'll ever need (be generous - I routinely use
10000).

Create a Query

INSERT INTO targettable
SELECT "Male" AS Gender
FROM [Num]
WHERE [N] < [Forms]![YourFormName]![[Male];

and execute it from the AfterUpdate event of [Male] or from a command
button on the form.
 
Back
Top