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 8055017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:16:29+00:00 2026-06-05T08:16:29+00:00

I have a query which uses an array of tables (stored as a string

  • 0

I have a query which uses an array of tables (stored as a string array) to loop through my tables and perform a Delete/Update set of queries. The queries are identical other than the table names, hence using a loop to iterate through using the table name as a variable.

The problem is, my Delete query locks the table and the Update query runs too quickly afterward; I get a “db is locked” error.

I need either of two things:

  1. A way to tell VBA to “wait for previous command” OR
  2. A way to concatenate these queries into one (or two) queries: one to delete the database rows and another to import the new ones. With this I could just run the queries from a standard access query (which should allocate proper time, finish queries etc)

The only catch to this is that there are parent-child relations, so the parent table has to be updated before its children (currently accomplished through array ordering).

Here’s the current code which (sometimes) produces the “DB locked/in use” message:

For i = 0 To UBound(tables)
    'Delete all data first
    sql = "DELETE * FROM " & tables(i)
    DoCmd.RunSQL sql
    'Update all data second
    sql = "INSERT INTO " & tables(i) & " IN """ & toDB & """ SELECT " & tables(i) & " .* FROM " & tables(i) & " IN """ & fromDB & """;"
    DoCmd.RunSQL sql
Next

Should clarify: the queries take one backend’s (fromDB) rows from identical tables and pushes it to another backend’s (toDB) rows

EDIT: In response to the questions regarding INSERT INTO, my problem with that is if I add fields to the toDB, it will delete them if I overwrite. The reason I have to do this backdoor approach is because the database is still in development, but is also being used with select tables. Updates and feature improvements are done daily. I cannot use a simple split-backend either, because the other computer accessing the database is not always on the network (we have to manually sync it when it returns to the network), so I work on one backend and it works on another, identical(ish, minus my schema update) backend.

  • 1 1 Answer
  • 0 Views
  • 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-06-05T08:16:31+00:00Added an answer on June 5, 2026 at 8:16 am

    You can use ADO instead of DoCmd.RunSQL to execute your SQL synchronously.

     Dim cmd As ADODB.Command
     Dim cnn As New ADODB.Connection
    
     Set cnn = CurrentProject.Connection
    
     For i = 0 To UBound(tables)
         Set cmd = New ADODB.Command
         With cmd
    
            .CommandType = adCmdText
             .ActiveConnection = cnn
            .CommandText = "DELETE * FROM " & tables(i)
            .Execute
          End With
    
         Set cmd = New ADODB.Command
         With cmd
    
            .CommandType = adCmdText
             .ActiveConnection = cnn
            .CommandText = "INSERT INTO " & tables(i) & " IN """ & toDB & """ SELECT " & tables(i) & " .* FROM " & tables(i) & " IN """ & fromDB & """;"
            .Execute
          End With
    
    Next
    

    You could also add cnn.BeginTrans and cnn.CommitTrans to make the two statements Atomic.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query which uses a cursor to cycle through the results of
I have a query which uses a complicated set of CASE statements, some nested,
I have a query which uses a self join on 2 tables to return
i have been working on query which uses compute by clause for avg and
i have SOQL query which queries for some records based on a where condition.
I have the following query which uses a date variable, which is generated inside
I have this query (shown below) which currently uses temporary and filesort in order
I have a query which uses the GROUP_CONCAT of mysql on an integer field.
I'm attempting to write a linq query which uses several tables of related data
I have this login form which uses AJAX to query a database for checking

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.