View Full Version : Copy Selected Column from one table to another
uzair_zaman
01-02-2011, 09:57 PM
Hi,
I have two tables (table1 and table2). What I want is, if I will select a column in table1 then i want to copy that selected row and paste it in to table2.
I am assuming that I have to somehow pickup the selected column from table1 and save the data into an array or variables and paste the data in to a column in table2.
I have already wasted alot of time in checking for the solution. Kindly advice?
Thanks in advance.
Regards,
Uzair
HiTechCoach
01-05-2011, 02:30 AM
If it were me, I would use an append query.
uzair_zaman
01-05-2011, 02:36 AM
Hi,
Thanks for your reply. I have actually solved it by adopting a different approach:
--------------------------------------
[FONT='Times New Roman','serif']Private Sub Command_Click()
Dim st As String
Dim db As DAO.Database
Set db = DBEngine(0)(0)
st = "Insert Into [DestinationTable] ([RecID]) Select [RecID] From [SourceTable] Where [RecID] = '" & Me.[RecID] & "';"
db.Execute st, dbFailOnError
Set db = Nothing
End Sub
---------------------------
I have used the concept of the above code to copy the column and paste it into another table using a Primary Key.
I am leaving the details here if someone else need it later on.
Thanks and regards,
Uzair
HiTechCoach
01-05-2011, 02:43 AM
Hi,
Thanks for your reply. I have actually solved it by adopting a different approach:
--------------------------------------
[FONT='Times New Roman','serif']Private Sub Command_Click()
Dim st As String
Dim db As DAO.Database
Set db = DBEngine(0)(0)
st = "Insert Into [DestinationTable] ([RecID]) Select [RecID] From [SourceTable] Where [RecID] = '" & Me.[RecID] & "';"
db.Execute st, dbFailOnError
Set db = Nothing
End Sub
---------------------------
I have used the concept of the above code to copy the column and paste it into another table using a Primary Key.
I am leaving the details here if someone else need it later on.
Thanks and regards,
Uzair
Actually that is exactly what I was suggesting since you did use an append query.
Your code can be simplified to be just:
Private Sub Command_Click()
Dim st As String
' build the append query SQL
st = "Insert Into [DestinationTable] ([RecID]) Select [RecID] From [SourceTable] Where [RecID] = '" & Me.[RecID] & "';"
' run the append query
CurrentDB.Execute st, dbFailOnError
End Sub
uzair_zaman
01-05-2011, 02:45 AM
Exactly. Thanks for your reply.
Regards,
Uzair
uzair_zaman
01-05-2011, 02:46 AM
Exactly. Thanks for your reply.
Regards,
Uzair
:yes
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.