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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:29:40+00:00 2026-06-09T09:29:40+00:00

I apologize for the cluster of code you’re about to receive. The question is:

  • 0

I apologize for the cluster of code you’re about to receive. The question is: why does my query work in the design window (note the Debug.Print .CommandText outputs the exact text I put into an access query), but comes up with Method ‘Execute’ of object ‘_Command’ failed and does not run the INSERT query. Here’s the code:

    cnn.BeginTrans 'Begin deletion
    cmdText = "DELETE * FROM tblB1B2"
    Set cmd = New ADODB.Command
    With cmd
        .CommandType = adCmdText
        .ActiveConnection = cnn
        .CommandText = cmdText
        .Execute
    End With
    cnn.CommitTrans 'Commit Deletion

    cnn.BeginTrans 'Begin update
    cmdText = "INSERT INTO tblB1B2 IN '" & toDB & "' " & _
                "SELECT interne AS interne, groupe AS groupe, MAX(itemref) AS [item], largeur AS largeur, hauteur AS hauteur, local AS [local], etage AS etage, partie AS partie, dessin AS dessin, datezonage AS datezonage, externe AS externe, erreur AS erreur, tag_hndl AS tag_hndl, tag_dessin AS tag_dessin, pobj_hndl AS pobj_hndl, pobj_type AS pobj_type, pobj_bname AS pobj_bname, zpl_hndl AS zpl_hndl, id AS id, Sidewalk AS Sidewalk, BarrierFreePathOfTravel AS BarrierFreePathOfTravel, Signage AS Signage, Hardware AS Hardware, PowerDoorOperator AS PowerDoorOperator, PDOMountHeight AS PDOMountHeight, ClearWidth AS ClearWidth, ClearSpace AS ClearSpace, ManoeuveringSpace AS ManoeuveringSpace, TwoDoorsInASeries AS TwoDoorsInASeries, Comments AS [Comments] " & _
                "FROM " & _
                    "(SELECT interne, groupe, [item] AS itemref, largeur, hauteur, local, etage, partie, dessin, datezonage, externe, erreur, tag_hndl, tag_dessin, pobj_hndl, pobj_type, pobj_bname, zpl_hndl, [id], Sidewalk, BarrierFreePathOfTravel, Signage, Hardware, PowerDoorOperator, PDOMountHeight, ClearWidth, ClearSpace, ManoeuveringSpace, TwoDoorsInASeries, [Comments] " & _
                    "FROM tblB1B2 IN '" & dbArray(0) & "' " & _
                "UNION ALL " & _
                    "SELECT interne, groupe, [item] AS itemref, largeur, hauteur, local, etage, partie, dessin, datezonage, externe, erreur, tag_hndl, tag_dessin, pobj_hndl, pobj_type, pobj_bname, zpl_hndl, [id], Sidewalk, BarrierFreePathOfTravel, Signage, Hardware, PowerDoorOperator, PDOMountHeight, ClearWidth, ClearSpace, ManoeuveringSpace, TwoDoorsInASeries, [Comments] " & _
                    "FROM tblB1B2 IN '" & dbArray(1) & "' " & _
                "UNION ALL " & _
                    "SELECT interne, groupe, [item] AS itemref, largeur, hauteur, local, etage, partie, dessin, datezonage, externe, erreur, tag_hndl, tag_dessin, pobj_hndl, pobj_type, pobj_bname, zpl_hndl, [id], Sidewalk, BarrierFreePathOfTravel, Signage, Hardware, PowerDoorOperator, PDOMountHeight, ClearWidth, ClearSpace, ManoeuveringSpace, TwoDoorsInASeries, [Comments] " & _
                    "FROM tblB1B2 IN '" & dbArray(2) & "' " & _
                ") AS FullTable " & _
              "GROUP BY interne, groupe, largeur, hauteur, local, etage, partie, dessin, datezonage, externe, erreur, tag_hndl, tag_dessin, pobj_hndl, pobj_type, pobj_bname, zpl_hndl, [id], Sidewalk, BarrierFreePathOfTravel, Signage, Hardware, PowerDoorOperator, PDOMountHeight, ClearWidth, ClearSpace, ManoeuveringSpace, TwoDoorsInASeries, [Comments]"

    Set cmd = New ADODB.Command
    With cmd
        .CommandType = adCmdText
        .ActiveConnection = cnn
        .CommandText = cmdText
        Debug.Print .CommandText
        .Execute
    End With
    cnn.CommitTrans 'Commit update

The printed text when copy-pasted into an access query runs fine; but produces this error in VBA. Why? How can I get around it? Am I using a keyword I’m not aware of?

Also, is there a way I can perform this query without specifying EACH field? (Note the MAX(itemref))

  • 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-09T09:29:42+00:00Added an answer on June 9, 2026 at 9:29 am

    Well.. after posting here (as usual, after about 3 hours of trial and failure).. I got it. Turns out “local” is a reserved keyword in JET. I had to do some creative manoeuvring to get it to recognize that it’s a field. For anyone else having this type of problem, here’s the fixed .CommandText:

    cmdText = "INSERT INTO tblB1B2 IN '" & toDB & "' " & _
                        "SELECT interne AS interne, groupe AS groupe, MAX(itemref) AS item, largeur AS largeur, hauteur AS hauteur, localref AS [local], etage AS etage, partie AS partie, dessin AS dessin, datezonage AS datezonage, externe AS externe, erreur AS erreur, tag_hndl AS tag_hndl, tag_dessin AS tag_dessin, pobj_hndl AS pobj_hndl, pobj_type AS pobj_type, pobj_bname AS pobj_bname, zpl_hndl AS zpl_hndl, id AS id, Sidewalk AS Sidewalk, BarrierFreePathOfTravel AS BarrierFreePathOfTravel, Signage AS Signage, Hardware AS Hardware, PowerDoorOperator AS PowerDoorOperator, PDOMountHeight AS PDOMountHeight, ClearWidth AS ClearWidth, ClearSpace AS ClearSpace, ManoeuveringSpace AS ManoeuveringSpace, TwoDoorsInASeries AS TwoDoorsInASeries, Comments AS Comments " & _
                        "FROM " & _
                            "(SELECT interne, groupe, item AS itemref, largeur, hauteur, [local] AS localref, etage, partie, dessin, datezonage, externe, erreur, tag_hndl, tag_dessin, pobj_hndl, pobj_type, pobj_bname, zpl_hndl, id, Sidewalk, BarrierFreePathOfTravel, Signage, Hardware, PowerDoorOperator, PDOMountHeight, ClearWidth, ClearSpace, ManoeuveringSpace, TwoDoorsInASeries, Comments " & _
                            "FROM tblB1B2 IN '" & dbArray(0) & "' " & _
                        "UNION ALL " & _
                            "SELECT interne, groupe, item AS itemref, largeur, hauteur, [local] AS localref, etage, partie, dessin, datezonage, externe, erreur, tag_hndl, tag_dessin, pobj_hndl, pobj_type, pobj_bname, zpl_hndl, [id], Sidewalk, BarrierFreePathOfTravel, Signage, Hardware, PowerDoorOperator, PDOMountHeight, ClearWidth, ClearSpace, ManoeuveringSpace, TwoDoorsInASeries, Comments " & _
                            "FROM tblB1B2 IN '" & dbArray(1) & "' " & _
                        "UNION ALL " & _
                            "SELECT interne, groupe, item AS itemref, largeur, hauteur, [local] AS localref, etage, partie, dessin, datezonage, externe, erreur, tag_hndl, tag_dessin, pobj_hndl, pobj_type, pobj_bname, zpl_hndl, [id], Sidewalk, BarrierFreePathOfTravel, Signage, Hardware, PowerDoorOperator, PDOMountHeight, ClearWidth, ClearSpace, ManoeuveringSpace, TwoDoorsInASeries, Comments " & _
                            "FROM tblB1B2 IN '" & dbArray(2) & "' " & _
                        ") AS FullTable " & _
                      "GROUP BY interne, groupe, largeur, hauteur, localref, etage, partie, dessin, datezonage, externe, erreur, tag_hndl, tag_dessin, pobj_hndl, pobj_type, pobj_bname, zpl_hndl, [id], Sidewalk, BarrierFreePathOfTravel, Signage, Hardware, PowerDoorOperator, PDOMountHeight, ClearWidth, ClearSpace, ManoeuveringSpace, TwoDoorsInASeries, Comments"
    

    Note around the local fields, I had to have [local] AS localref in the subqueries and localref AS [local] in the main query to avoid both keywords and circular referencing.

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

Sidebar

Related Questions

I apologize profusely for the incredibly newbish question I'm about to ask, but for
I apologize if my question does not make sense. As you can see from
I apologize for the newb question but have not found a solution online. I
I apologize in advance, if this question doesn't make sense. I'm a newbie. I
I apologize in advance for not knowing how to better state this question. In
Earlier on i post a question about visualization and clustering. I guess my question
I apologize for the newbie question as I am a newbie in developing for
I apologize if this question was already asked but I can't seem to find
I apologize for the silliness of the question but am a complete neophyte with
I apologize in advance because this is somehow a silly question, but I just

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.