I want to copy two fields from one table to another

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Snowowl
    New Member
    • Mar 2010
    • 1

    I want to copy two fields from one table to another

    First let me admit I'm a newbie with Access....

    I am updating a table using one form and want to copy two of the table fields to another table upon clicking save.
    I see commands to copy the full record, but want to copy just two fields.

    How do I do this?
  • patjones
    Recognized Expert Contributor
    • Jun 2007
    • 931

    #2
    If you could post what the structure of the tables are, that would be great...and also whether you are trying to do this using VBA. And, when you say two of the table fields, do you mean two of the fields from just one record?

    Pat

    Comment

    • beacon
      Contributor
      • Aug 2007
      • 579

      #3
      You will need to either create an Append Query or, if you're going to use VBA, run a SQL statement from a module or subroutine.

      To create an Append Query, just create a new query in Design View. Go to Query on the menu and select Append Query. It will ask you which table you want to add records to...this is the destination table. Then, you'll identify the field that needs to be updated.

      Then, on your form, use your Save command to update the Append Query you just created and it will automatically add the records to your table.

      If you are going to take the VBA route, you'll enter the following code being sure to put your actual table info in where it says [yourTable] or something similar:

      Code:
      INSERT INTO [destinationTable] ( Field1, Field2 )
      SELECT [yourTable].Field1, [yourTable].Field2
      FROM [yourTable]
      If you need to select these fields based on a condition, you'll add a WHERE clause, like so:

      Code:
      WHERE ((([yourTable].Field1)= " & varFieldData & "));"
      varFieldData would be a variable that holds the data, although you could type the data that the condition is based on directly into the WHERE clause by removing the ampersands (&) and the double quotes (") immediately adjacent to the ampersands (&).

      You won't need to put the square brackets around [yourTable] either. I just added those to help make it easy to see which table I was referring to at any time. Probably goes without saying, but you will have to change Field1 to the actual name of the field that you are trying to copy data from.

      Comment

      Working...