Add records to table

  • Thread starter Thread starter Saturn
  • Start date Start date
S

Saturn

I need to populate a table at the click of a button
control. Can someome provide me with a sample set of
instruction to code in the click event for the button
object? Use as an example a table called "components" with
three fields; customer_id, component_id, and price. In
actuality, there will be about a dozen fields set per
record and up to 50 records created per iteration.
The instructions need to set the record field values and
save the record (I guess ???). I will be creating dozens
of records (different field values) for each new customer.
Some of the field values will be taken from fields on the
form, but the majority will be hardcoded.
Thanks!
-Howard
 
Try this

Public Sub Button1_Click(

Dim rst as Objec
Set rst = CurrentDb.OpenRecordset("components"

rst.AddNe

rst!customer_id = me.customer_i
rst!component_id = me.component_i
rst!price = me.pric

rst.Updat

End Su

Hope this helps
Fran


----- Saturn wrote: ----

I need to populate a table at the click of a button
control. Can someome provide me with a sample set of
instruction to code in the click event for the button
object? Use as an example a table called "components" with
three fields; customer_id, component_id, and price. In
actuality, there will be about a dozen fields set per
record and up to 50 records created per iteration
The instructions need to set the record field values and
save the record (I guess ???). I will be creating dozens
of records (different field values) for each new customer.
Some of the field values will be taken from fields on the
form, but the majority will be hardcoded.
Thanks
-Howar
 
Thank you! Thank you! Thank you! Thank you! Thank you!
Thank you! Thank you! Thank you! Thank you! Thank you!
Thank you! Thank you! Thank you!
Many have tried, but only you have succeeded. Simple when
you know what you are doing, I guess. Thanks again!
-Howard
 
You wouldn't happen to be able to pull out of your hat a way to use this same code with a prompt for "How many given" and have that many new records created on that one response

Pseudo sort

Public Sub Given_To_Click(

Dim rst as Objec
Dim int as Number Give
Set rst = CurrentDb.OpenRecordset("hummingbird") 'Name of databas
int =

If ([Number Given]) = 25

rst.AddNe

rst!Given_To = me.Given_T
rst!Date_Given = me.Date_Give

rst.Updat

End Su

Sorta something like this
 
You wouldn't happen to be able to pull out of your hat a way to use this same code with a prompt for "How many given" and have that many new records created on that one response?

It's handy to have an auxiliary table (I call mine NUM, with a single
long integer field N, with values 0 through 10000 or so).

Create an Append query based on the data you want to append, with a
Cartesian Join (i.e. no join line) to NUM. Put a criterion on N of

< [HowManyGiven]

and you'll get that many duplicates of the record.
 
Back
Top