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

  • Home
  • SEARCH
  • 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 8401915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:55:22+00:00 2026-06-09T21:55:22+00:00

I am trying to avoid using multiple INSERT SQL queries but if I must

  • 0

I am trying to avoid using multiple INSERT SQL queries but if I must I will. I have read over there that you can simply use INSERT INTO table(field) SELECT 'value' UNION ALL SELECT ... however I am having trouble with the syntax of it under MS Access 2007. I have tried a few variants but none works: I always get either “incorrect syntax” or “missing operator” error. I have tried with and without the ALL qualifier, with and without the SELECT keyword, etc. Here’s how I am creating the query using VBA:

sql_query = "INSERT INTO " & tmp_tbl_name & " (transit)"
For Each xlCell In xlRange
    sql_query = sql_query & " SELECT '" & xlCell.Value & "' "
    sql_query = sql_query & "UNION"
Next xlCell
sql_query = Mid(sql_query, 1, Len(sql_query) - 6)
DoCmd.RunSQL (sql_query)

Here’s a shortened sample of the query I am generating:

INSERT INTO tmp_tbl_2012_08_17_15_44_03 (transit) 
SELECT 'L02_NA010001' 
  UNION 
SELECT 'L13_PB010001' 
  UNION 
SELECT 'L31_US020001' 
  UNION 
SELECT 'L33_EX020010'
  ...

The table has only one VARCHAR(255) field and no relations to any other table (it’s a temporary table to process a few things and keep only some elements of it).

Many thanks !

  • 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-09T21:55:24+00:00Added an answer on June 9, 2026 at 9:55 pm

    I think you can use good ol’ DAO to do this rather quickly:

    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    
    Set db = CurrentDb
    Set rs = db.OpenRecordset("tmp_tbl_2012_08_17_15_44_03", dbOpenDynaset)
    
    For Each xlCell In xlRange
        With rs
            .AddNew
            .Fields("transit") = xlCell.Value
            .Update
        End With
    Next xlCell
    
    rs.Close
    db.Close
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to avoid using Net::SSH::Perl library since there is some problems in
I have a file at a URI that I would like to read using
Is there a way to specify using JPA that there should be multiple unique
I'm trying to avoid using queries in while loops. Therefore I've come to the
From the get go, let me say that I'm trying to avoid using pcntl_fork()
I have the problem that I will have multiple servers that perform jobs. They
I'm trying to update multiple columns in a MS SQL statement using a sub-query.
We're trying to have maven deploy to many multiple servers that form our cluster
I'm trying to avoid using Interface Builder as much as possible. At the moment
I'm probably over-thinking this/wasting time trying to avoid a bit of conditional code -

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.