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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert only certain IDs 1

Status
Not open for further replies.

briglass

Programmer
Dec 4, 2001
179
GB
Hello,

Right now I have a statement in VB6 that inserts all the contents of one table into another. However, I would like to only select a certain ID from that table.

Here is what I have now:

Code:
strsql$ = "INSERT INTO table1 SELECT table2.* FROM table2;"
db.Execute strsql$

How can I modify this statement to only select a certain ID from the table?



Thanks, (-:
Brian
 
Add a where clause in the SQL:
Code:
strsql$ = "INSERT INTO table1 SELECT table2.* FROM table2 "  & _
    "WHERE ID = 1"
db.Execute strsql$

Duane
MS Access MVP
Find out how to get great answers faq219-2884.
 
Thanks for your feedback!

I seem to be having a problem with this solution. My final string looks like this:

Code:
"INSERT INTO table1 SELECT table2.* FROM table2 WHERE ID = 01"

However, I receive an error 3464: Data type mismatch in criteria expression. The line also does not work when I add a semicolon to the end.

Any ideas?



Thanks, (-:
Brian
 
You hadn't stated that your ID field is text rather than numeric. Text values must be delimited with quotes:
Code:
"INSERT INTO table1 SELECT table2.* FROM table2 WHERE ID = '01'"

Duane
MS Access MVP
Find out how to get great answers faq219-2884.
 
That worked. Thank you very much!



Thanks, (-:
Brian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top