Adding new record into a table by using code

  • Thread starter Thread starter Art Vandaley
  • Start date Start date
A

Art Vandaley

Hi,

I want to add new records into a table's fields by using code. Can anybody
help me to have an idea how such a code should be? Regards.
 
Art,

It would depend a lot on what the data is that you want to add to the
table, where it comes from, and when you want to perform this. But it
may be a job for an Append Query, so it may help you to have a look at
this for a start.
 
Hi,

I need to do it by using code. I have a command buton in a form which will
start the code (command_click()). Say I have fields "number", "name" in
table t1. I want to add 10 new records automatically with the command button
clicking. The fields woulb be filled like:

number------name
100---------Tom
101---------Tom
102---------Tom
.......
.......
.......
110---------Tom

I'll appreciate having your answer. Regards.
 
Art said:
Hi,

I need to do it by using code. I have a command buton in a form which will
start the code (command_click()). Say I have fields "number", "name" in
table t1. I want to add 10 new records automatically with the command button
clicking. The fields woulb be filled like:

number------name
100---------Tom
101---------Tom
102---------Tom
......
......
......
110---------Tom

I'll appreciate having your answer. Regards.

Steve's answer is still the solution.

If you really just want a sequence n to n+9 inclusive, where n is the next
number available, you would just make this field be an autonumber field and just
run the append query 10 times. In this case you create the query as an append
query just as if you were going to run it manually, and to run it in code use
the docmd.OpenQuery method.

If you specifically want the numbers to be 100-109, the process is similar, but
in this case you use docmd.RunSQL instead and code in the 100-109 values one at
a time. (You could do this above also if you prefer). To create the SQL, just
use the wizard to create the same query as described above, then from design
view switch to SQL view to see the SQL. The statements you see will execute the
same query when ginen to the docmd.RunSQL method as a string. So you can just
modify the string for the numbers 100-109, one at a time (in a for-next loop)
and rerun the docmd.RunSQL (String_Of_SQL_Code_Here).

gm
 

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

Back
Top