Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 849557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:07:20+00:00 2026-05-15T07:07:20+00:00

i have 2 tables in access this is what i need: 1. if the

  • 0

i have 2 tables in access

this is what i need:

1. if the PK from table1 exists in table2, then delete the entire record with that PK from table2 and add the entire record from table1 into table2
2. if the PK does not exist then add the record

i need help with both the sql statement and the VBA

i guess the VBA should be a loop, going through every record in table1. inside the loop i should have the select statement

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T07:07:21+00:00Added an answer on May 15, 2026 at 7:07 am

    I don’t think you need a VBA loop, just two SQL statements.

    First delete the matching rows from table2.

    DELETE 
    FROM table2 AS m
    WHERE pk IN (SELECT pk FROM table1);
    

    Then append all the rows from table1 into table2.

    INSERT INTO table2 (
        pk,
        field2,
        field3,
        field4)
    SELECT
        i.pk,
        i.field2,
        i.field3,
        i.field4
    FROM
        table1 AS i;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 3 tables on which i need to select data from using ms-access
So I have an awful query that current exists in MS Access that I
In Access 2007, I have two tables related such that the (surrogate) PK of
I have a little exercise where I need to access data from a view
good morning. We need to copy tables from Access to SQL. Thing is the
I can't solve this on MS Access SQL. I have a foo table with
Have 2 tables in Access 2007, both lists of certain tasks to be accomplished.
Say we have two tables in an MS Access db: Service Users: | ID
I have an access database with these tables: - sequences: it describes the sequences
I have an Access database (in Access 2003) with several tables, and data must

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.