ADO error message

≯℡__Kan透↙ 提交于 2019-12-24 07:56:35

问题


I am getting an error message while trying to update one excel table from another excel table in a different (and closed) workbook. The error only appear when the source workbook is not in a .xls format.

You cannot edit this field because it resides in a linked Excel spreadsheet. The ability to edit data in a linked Excel spreadsheet has been disabled in this Access Release.

This is supposed to be an expected behavior when using Access.

  1. Why am I seeing this error as I'm not working with Access but only two Excel files, and with a more recent version than 2007 ?
  2. How does this feature improve security ?
  3. Is there a workaround in my case ? Other than using a temp table in my target workbook.

UPDATE : Code example

Sub GetFiles()
    'Take !M sheet to create files and their informations
    Dim Base As FichierSource

    '----------------------------
    'Create files object
    '----------------------------

    'Fichier Source
    Base.Path = "C:\Users\Lichar\Documents\SQL TEST\Base.xlsx"
    Base.SourceSheet = "Data"
    Base.TargetSheet = "Base"
    Base.Columns = "*"
    Base.Filter = "WHERE [Base$].id = [Data$].id"
    Base.Name = "Base.xlsx"


    '---------------------------
    'Launch queries
    '---------------------------

    With Base
        Call UPDATEQUERY(.Path, .SourceSheet, .TargetSheet, .Columns, .Filter)
    End With

End Sub

Sub UPDATEQUERY(SourcePath As String, SourceSheet As String, TargetSheet As String, _
Columns As String, Filter As String)

    Dim Cn As ADODB.Connection
    Dim QUERY_SQL As String
    Dim CHAINE_HDR As String
    Dim STRCONNECTION As String

    CHAINE_HDR = "[Excel 12.0;Provider=Microsoft.ACE.OLEDB.12.0;Mode=5;Extended Properties='HDR=YES;'] "

    Set Cn = New ADODB.Connection

    QUERY_SQL = _
    "UPDATE [" & TargetSheet & "$] INNER JOIN (SELECT * FROM [" & SourceSheet & "$] " & _
    "IN '" & SourcePath & "' " & CHAINE_HDR & ") t2 " & _
    "ON [" & TargetSheet & "$].id = t2.id " & _
    "SET [" & TargetSheet & "$].ColA = t2.ColA "

    STRCONNECTION = _
    "Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};" & _
    "DriverId=790;" & _
    "Dbq=" & ThisWorkbook.FullName & ";" & _
    "DefaultDir=" & ThisWorkbook.FullName & ";ReadOnly=False;"

    Cn.Open STRCONNECTION
    Cn.Execute (QUERY_SQL)

    '--- Fermeture connexion ---
    Cn.Close
    Set Cn = Nothing

End Sub

Thanks


回答1:


That's three questions in one, but I'll try to answer all of them:

  1. It's not dependent on Access or Excel, but on the Microsoft Access OLEDB provider as far as I know. You can attempt to use an ODBC connection using the Microsoft Excel ODBC driver
  2. One Stack Overflow answerer saying it's because of security reasons is not that good of a source. I doubt it's because of security reasons.
  3. There are lots. If you tell us what you want to do exactly, I can be more specific.


来源:https://stackoverflow.com/questions/47001575/ado-error-message

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!