Consulting

Results 1 to 6 of 6

Thread: Copy Selected Column from one table to another

  1. #1

    Smile Copy Selected Column from one table to another

    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

  2. #2
    If it were me, I would use an append query.
    Boyd Trimmell aka HiTechCoach
    Microsoft Access MVP -2010-2015

    Programming: Nine different ways to do it right, a thousand ways to do it wrong.
    Binary--it's as easy as 1-10-11

  3. #3

    Thanks

    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

  4. #4
    Quote Originally Posted by uzair_zaman
    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:

    [VBA]

    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

    [/VBA]
    Boyd Trimmell aka HiTechCoach
    Microsoft Access MVP -2010-2015

    Programming: Nine different ways to do it right, a thousand ways to do it wrong.
    Binary--it's as easy as 1-10-11

  5. #5

    Thanks

    Exactly. Thanks for your reply.
    Regards,
    Uzair

  6. #6
    Exactly. Thanks for your reply.
    Regards,
    Uzair

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •