+ Reply to Thread
Results 1 to 4 of 4

vba method 'execute' of object '_Connection' failed

  1. #1
    Registered User
    Join Date
    01-25-2015
    Location
    Barcelona, Spain
    MS-Off Ver
    2010
    Posts
    5

    Question vba method 'execute' of object '_Connection' failed

    Hello all,
    I have an issue on VBA when exporting a table inside a database into another table with a select query.
    I get the error:

    method 'execute' of object '_Connection' failed

    The problem is that if I include in the query a field called 'Size' which is the only one with double precision I get the error, if not the script runs ok.

    The code:

    Set rs = conn.Execute("SELECT " + tblname + ".Ctry, " + tblname + ".Ctry2, " + tblname + ".UniqueAgglomerationId as UniqueAgglomerationId10, " + tblname + ".RLID as RLID10, " + tblname + ".NumberOfInhabitants as NumberOfInhabitants10, " & _
    tblname + ".Size as Size10, " + tblname + ".DeliveryID as DeliveryID10, " + tblname + ".DeliveryStr as DeliveryStr10, " + tblname + ".AggloNameEn as NameEn10, " + tblname + ".Link as Link10 INTO agg_05_10 IN '" + Me.Dir1.Path + "\" + Ctrycode + "_inter.accdb' FROM " + tblname + " WHERE " & _
    CC + ";", , adCmdText)

    What could be leading to the error?
    Regards,

    Francisco

  2. #2
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: vba method 'execute' of object '_Connection' failed

    Is probably reserved word. You may try to use .[Size] in place of .Size
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

  3. #3
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,851

    Re: vba method 'execute' of object '_Connection' failed

    Check this list of SQL reserved words

    https://msdn.microsoft.com/en-us/lib...ectionSection7
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  4. #4
    Registered User
    Join Date
    01-25-2015
    Location
    Barcelona, Spain
    MS-Off Ver
    2010
    Posts
    5

    Re: vba method 'execute' of object '_Connection' failed

    Thanks a lot! It worked fine with the .[Size] solution!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Method 'To' of object '_MailItem failed
    By winwall in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-20-2020, 08:57 AM
  2. help with method range of object failed
    By ammartino44 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-12-2015, 02:44 PM
  3. Method 'Run' of object '_Application' failed
    By brl8 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 04-21-2015, 04:27 AM
  4. Method 'top' of object 'plotarea' failed
    By leafbiffen in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-16-2013, 03:11 AM
  5. [SOLVED] Method range of object failed
    By Aland2929 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 04-02-2013, 06:55 AM
  6. Object error - method failed
    By okriskao in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-24-2009, 02:02 AM
  7. Method Add of object Sheet failed
    By JonMitsu in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-10-2006, 03:29 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1