Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

append query in code 1

Status
Not open for further replies.

autex

Technical User
Jan 11, 2005
75
US
RoyVidar just showed me how simple it is to do delete query in code. I was using recordsets. I thought I'd try and do an append query the same way, but I'm having trouble finding an example. This is what I got.

strsql = "Insert into [table1], [field 1] = 100"

This is just a test db. Table one is the table and field 1 is one of two fields. Would someone please show me the syntax for appending a record with entries in more than one field? thanks.
 
One way:
INSERT INTO Table1 (Field1, Field2) VALUES (Value1, Value2)
Another way:
INSERT INTO Table1 (Field1, Field2) SELECT Col1, Col2 FROM Table2 WHERE SomeCondition

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
If you start by creating an append query in the querybuilder, then switch to SQL view, you'll find working syntax. Something like this?

[tt]strsql="insert into table1 (field1) values (100)"
currendb.execute strsql[/tt]

- and thanx for the kind words!

Roy-Vidar
 
Hi. Try

INSERT INTO YourTable ( TableField ) SELECT 1 AS [Num];

You have to provide in the () the list of fields, in the order that your selection will appear.

example ( TableField1, TableField2 ... )

ChaZ

There Are 10 Types Of People In The world:
Those That Understand BINARY And Those That Don’t.
 
Wow, lots of posts appeard while I was typing!

There Are 10 Types Of People In The world:
Those That Understand BINARY And Those That Don’t.
 
thanks everybody. I feel like I should have know this already. oh well.
 
Dim sql, users As String

users = Environ("username")
sql = "Insert into [db checkers t](user,date) values(users,now)"

CurrentDb.Execute sql

I guess I thought this would be super easy, I'm getting a syntax error. I have an autonumber field in this table also. I don't know if I have to add to all the fields or what. Hopefully somebody is still following this string.
 
sql = "Insert into [db checkers t]([user],[date]) values('" & users & "',#" & Now() & "#)"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top