By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,945 Members | 1,692 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,945 IT Pros & Developers. It's quick & easy.

How can I Insert into a table with data from a form

P: n/a
Hi,
Right now I have a form with a couple of fields. Let say: Name and
Date. Now I want to create an append query to insert these data into a
table with the field of Name and Date. I am not very familiar with
append query. Anybody know what is the sql statement that can do this?
Any help would be appreciated.

Thanks
Khoa

Apr 28 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
If you use the query wizard

1) new query
2) from menu line select Apend query and it will as you what table and
you select the table mentioned above.
3) In one of the columns go to 'append to' and select Name
4) go to the top line for that same column and right click and chose
build
then forms
then all forms
pick the form that has the name filed
pick the name field
pick value on far right and double click
5 Repeat steps 3 and 4 for the date.
close the query and name it what you want. (example AppendNameQuery

Now back on the form, select the event (button click or whatever you
want to use to trigger this append.
write the code
docmd.setwarnings false set the warnings off
docmd.openquery "AppendNameQuery"
docmd.setwarnings true reset to give warnings if you
turned them off

Apr 28 '06 #2

P: n/a
Is there a reason you don't want to bind the form to the table by
setting the Recordsource property?

Apr 28 '06 #3

P: n/a
if u want to use VBA use this

dim rs as recordset
dim db as database
set db = currentdb

set rs=db.openrecordset("select * from table '"+<tablename>+"')
with rs
..addnew
![date]=txtdate
![name]=txtname
..update
end with
or u can use

db.execute("insert into table <tablename> set name ='"+txtname'");

'u may want to do some modifications ....the code may not exactly
correct....

Apr 30 '06 #4

P: n/a
Thank you: Ron2005, pietlin...@hotmail.com, roade...@gmail.com for all
the help. I was able to create an append query and to insert new row
into the table. However, the query does not insert one row but as many
row as I have in the table before. For example, if I have 5 rows in the
original table, it will insert 5 duplicate rows (This was possible
because i have an autonumber field). Does anybody know how to limit it
to insert only 1 row?

Thanks in advance.

May 1 '06 #5

P: n/a
Just an update to my problem. I found out that the only reason it
create problem when I tried to append was because i use a field from
another table. Once I got rid of the link/connection I was able to add
1 row only. Thanks

May 1 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.