Adding Records to a table

N

Nancy

I have a database where I want take a number from a form
[Num1] and add that many records to a table [Table1].
In the form, I have a list box which lists the job
numbers. I wanted to use a for loop and add each of the
jobnumbers using the .itemdata() property.

I can't seem to figure out how to add the records.
Along with adding the job number into the new records, I
would like to add the current date.

Thanks for any help.
 
A

Alex Dybenko

you can use DAO
say strJobNum hold a value you wan to add, then you can run:

dim rst as dao.recordset
set rst=currentdb.openrecordset("Select * from table1", dbopendynaset)
rst.addnew
rst!JobNum=strJobNum
rst!JobDate=DATE()
rst.update
rst.close

replace JobNum and JobDate with proper names of your table field names
 
N

Nancy

I don't know what DAO is, and I don't know how to use it.
WHen I paste that into visual basic, it gives me an
error. How do I use DAO, or is there another method to
adding the tables.

-----Original Message-----
you can use DAO
say strJobNum hold a value you wan to add, then you can run:

dim rst as dao.recordset
set rst=currentdb.openrecordset("Select * from table1", dbopendynaset)
rst.addnew
rst!JobNum=strJobNum
rst!JobDate=DATE()
rst.update
rst.close

replace JobNum and JobDate with proper names of your table field names

--
Alex Dybenko (MVP)
http://Alex.Dybenko.com



I have a database where I want take a number from a form
[Num1] and add that many records to a table [Table1].
In the form, I have a list box which lists the job
numbers. I wanted to use a for loop and add each of the
jobnumbers using the .itemdata() property.

I can't seem to figure out how to add the records.
Along with adding the job number into the new records, I
would like to add the current date.

Thanks for any help.


.
 
A

Alex Dybenko

in this case try to use append query
start new query design, change type to append query, then you can set
reference to your listbox, to insert date - use function date
now you can run this query either using macro openquery, VB code
docmd.openquery "myquery"

--
Alex Dybenko (MVP)
http://Alex.Dybenko.com


Nancy said:
I don't know what DAO is, and I don't know how to use it.
WHen I paste that into visual basic, it gives me an
error. How do I use DAO, or is there another method to
adding the tables.

-----Original Message-----
you can use DAO
say strJobNum hold a value you wan to add, then you can run:

dim rst as dao.recordset
set rst=currentdb.openrecordset("Select * from table1", dbopendynaset)
rst.addnew
rst!JobNum=strJobNum
rst!JobDate=DATE()
rst.update
rst.close

replace JobNum and JobDate with proper names of your table field names

--
Alex Dybenko (MVP)
http://Alex.Dybenko.com



I have a database where I want take a number from a form
[Num1] and add that many records to a table [Table1].
In the form, I have a list box which lists the job
numbers. I wanted to use a for loop and add each of the
jobnumbers using the .itemdata() property.

I can't seem to figure out how to add the records.
Along with adding the job number into the new records, I
would like to add the current date.

Thanks for any help.


.
 

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

Top