Results 1 to 6 of 6
  1. #1
    schwachmama is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2012
    Posts
    7

    Runtime Error 2501 on docmd.runSQL

    Hi,


    The code below works fine on my work computer but an error code pops up on my co-workers computer.

    Code:
    Dim strTname As String
    strTname = "'tbl_Res_Analytical_S'"
    DoCmd.RunSQL ("update tbl_Tablefields set inImpList = true where tname in (" & strTname & ")")
    If its changed to execute it works fine e.g.

    Code:
    dbA.Execute ("update tbl_Tablefields set inImpList = true where tname in (" & strTname & ")")
    I believe its a docmd error and there are a lot of other docmd code through out the batch and I don't want to have to go through and change each one. Any ideas why this would happen?

    tbl_Tablefields = Table
    inImpList = field in tbl_Tablefields, true/false
    tname = field in tbl_Tablefields, text (255)

    thanks.
    Last edited by schwachmama; 04-16-2015 at 06:58 PM.

  2. #2
    NoellaG's Avatar
    NoellaG is offline VIP
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,043
    Hi,

    if it works on your computer and your collegue is getting an application/object defined error, it could be a missing reference. Check the window VBA -> Tools -> References for missing references on her computer.

  3. #3
    schwachmama is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2012
    Posts
    7
    Thanks NoellaG but sadly our object libraries don't look different. We have the exact same 5 objects defined.
    ·
    Visual Basic For Applications

    · Microsoft Access 14.0 Object Library

    · OLE Automation
    · Microsoft Office 14.0 Access database engine object library
    · Microsoft Office 14.0 Object Library

    But I know that I have previously installed other libraries..I just can't remember what or when.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,900
    What is the exact error message?

    I use Execute and don't have to bother with turning off/on warning messages with SetWarnings.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    schwachmama is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2012
    Posts
    7
    Thank June7...I re-looked at ALL the error codes that were popping up and realized that the reason for the error was actually happening earlier in the code. Below was the original code and the error that popped up was "about to update 0 row(s)". If I clicked yes, it would get stuck in a never ending loop. If I clicked no, I would get a runtime error 2501.

    Code:
    Dim j, k  As Integer
    For j = 0 To dbA.TableDefs.Count - 1
     For k = 0 To dbA.TableDefs(j).Fields.Count - 1
         dbA.Execute ("insert into tbl_Tablefields (tname, fname, ftype) values ('" & dbA.TableDefs(j).Name & "','" & _
         dbA.TableDefs(j).Fields(k).Name & "','" & dbA.TableDefs(j).Fields(k).Type & "')")
      Next k
    
    Dim strTname As String
    strTname = "'tbl_Res_Analytical_S'"
    DoCmd.RunSQL ("update tbl_Tablefields set inImpList = true where tname in (" & strTname & ")")
    
    Next j
    When I move next j right after next k and then run my docmd all works. I'm fine with the change in logic, but now my co-workers computer wants to confirm every action. I've added the code below and it stops asking for the confirmations but I guess now my issue has changed slightly to why does my co-workers computer have to confirm actions but mine does not. And why did the original code work on mine and not my co-workers? But I guess that's a question for another thread.

    Code:
    Application.SetOption "Confirm Action Queries", 0

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,900
    Don't know why one gets warnings and other doesn't. Execute should not be accompanied with warning message.

    But I don't quite understand this code - how can the INSERT work when there is only one VALUES parameter?

    Are you saying the posted code is not the final version?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 01-13-2015, 04:54 PM
  2. Replies: 2
    Last Post: 08-05-2013, 01:56 PM
  3. runtime error 2501 openform action was canceled
    By rumenrs in forum Programming
    Replies: 2
    Last Post: 04-11-2013, 04:29 AM
  4. Compile Error: Syntax Error in DoCmd.RunSQL Statement
    By Evilferret in forum Programming
    Replies: 1
    Last Post: 08-27-2012, 12:32 PM
  5. Syntax Error with DoCmd.RunSQL
    By dandoescode in forum Programming
    Replies: 2
    Last Post: 06-25-2012, 11:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums