Inset new column to a Query by VBA

ice051505

Registered User.
Local time
Yesterday, 18:17
Joined
Feb 11, 2013
Messages
42
Hi Dear all, I have Query A and Query B, and I want to insert a new column to A from the exist column in B, here is my code:

"INSERT INTO A (col_3) VALUES (SELECT col_3 FROM B " & _
"WHERE A.id = B.id ;"

Please provide me the correct way to do that, thanks
 
Can you explain exactly what you are trying to achieve :confused:

The SQL INSERT INTO clause is used to insert data (as a new record) into a table.
 
Here is the sample:

I have query A like below:
id col_1 col_2
1
2
3
4
5
...
and query B like below:
id col_3
2
3
5
6
...

Now I want to write VBA code to insert the entire column of col_3 from query B into query A, where the B.id=A.id

Data type on col_1,2,3 are text

Can you help me to correct the code?

Can you explain exactly what you are trying to achieve :confused:

The SQL INSERT INTO clause is used to insert data (as a new record) into a table.
 
Can you post same representative data? (Access '03, version for preference as that's all I have access to currently)
 
OK, I'm currently using Access 2002
Here is the data

Query A
id col_1 col_2
R1 UA UC
R2 UT UW
R3 UBC SFU
R4 UL MacE
R5 UV UNBC
R6 Queen UO
......

Query B
id col_3
R2 ON
R3 BC
R4 AB
R6 ON

The result in QueryA I want is like below
id col_1 col_2 col_3
R1 UA UC
R2 UT UW ON
R3 UBC SFU BC
R4 UL MacE AB
R5 UV UNBC
R6 Queen UO ON
......

Is that possible to do?

Can you post same representative data? (Access '03, version for preference as that's all I have access to currently)
 
Have you considered just joining the two queries on the ID field and returning all three columns in another query? Based on your sample desired results, you would want a Left join.
 
I don't want to creat more query though, I will think about it, Thanks
 

Users who are viewing this thread

Back
Top Bottom