Exception when trying to execute “REPLACE” against MS Access

前端 未结 4 376
我寻月下人不归
我寻月下人不归 2020-12-02 00:24

I\'m trying to execute an SQL query against a MS Access database containing a \"REPLACE\" function:

UPDATE MyTable 
   SET MyColumn = REPLACE(MyColumn, \'MyO         


        
相关标签:
4条回答
  • 2020-12-02 00:33

    In interactive Access, the Access Expression Service takes care of providing you access to user-defined and VBA functions, but the Access Expression Service is not available from outside Access. When accessing Jet/ACE data via ODBC or OLEDB, only a limited number of functions are available. Replace() is not one of them. However, you may be able to use InStr() and Len() to replicate the functionality of the Replace() function, but it would be fairly ugly.

    0 讨论(0)
  • 2020-12-02 00:42

    I confirm "Sandboxed mode" fix the problem with "Replace" function.

    Details of sandbox mode : https://support.office.com/en-au/article/Functions-and-properties-in-Access-2007-blocked-by-sandbox-mode-9a829783-f7a8-4a9f-8d43-8650b8cc9565

    0 讨论(0)
  • 2020-12-02 00:48

    Not sure if this is related to the problem you are having but I was having a problem running an update that contained a replace function in Access 2010 that would just return with no error - nothing. I was actually running it from OleDb in .NET and finally figured out I needed to set a registry key to turn off "Sandboxed Mode".

    http://office.microsoft.com/en-us/access-help/use-sandbox-mode-in-access-2007-HA010167429.aspx

    Hope that helps.

    0 讨论(0)
  • 2020-12-02 00:50

    it is impossible to get the REPLACE to work, maybe you know of some alternative solution?

    Here's the "fairly ugly" alternative approach alluded to by @David-W-Fenton:

    UPDATE MyTable 
       SET MyColumn = MID(
                          MyColumn, 
                          1, 
                          INSTR(MyColumn, 'MyOldSubstring') 
                             - 1
                         ) 
                         + 'MyNewSubstring'
                         + MID(
                               MyColumn, 
                               INSTR(MyColumn, 'MyOldSubstring') 
                                  + LEN('MyOldSubstring'), 
                               LEN(MyColumn) 
                                  - INSTR(MyColumn, 'MyOldSubstring') 
                                  - LEN('MyOldSubstring')
                                  + 1
                              )
     WHERE INSTR(MyColumn, 'MyOldSubstring') > 0
           AND Id = 10;
    
    0 讨论(0)
提交回复
热议问题