Updating Oracle Table from Excel VBA Macro using ODBC connection

孤人 提交于 2019-11-29 16:21:16

Provider "MSDASQL" is Microsoft's OLE DB Provider for ODBC Drivers. It is quite old, and is now deprecated. It is really only for use with older databases for which there are no OLE DB providers. It is also 32-bit-Only, so it won't work with 64 bit providers (such as the one you are trying to use). You would be better off trying an OLE DB driver.

The MS OLEDB provider for Oracle is "MSDAORA" (which should be pre-installed on your machine) and Oracle's own OLEDB provider is "OraOLEDB.Oracle". You would be best advised to download the latest Oracle-provided provider, as MSDAORA is also deprecated.

You would need to download and install the Oracle provider (if you haven't already)

.Provider = "OraOLEDB.Oracle"

You would also need to set the .ConnectionString. Have a look at http://www.connectionstrings.com/oracle-provider-for-ole-db-oraoledb/ for some examples.

Apparently the 'Run-time error '-2147467259 (80004005)' is excel's default 'There was a problem with Oracle and I dont know what it is.

First I found out that my odbc was pointing to an old DB that no longer existed. After updating the odbc, I still got the same error.

However the error no longer happened on the '.Open' portion, but on the .Execute where I was attempting to do an update. Eventually I figured out that the user did not have access to do an update to the table I was targeting.

So when you get an 'Run-time error '-2147467259 (80004005)' error, check your connections and permissions, they are likely wrong.

Here is the final code I used that worked after fixing permissions:

Sub Upload_Click1()
    Dim Oracon
    Dim recset
    Dim cmd

    Set Oracon = CreateObject("ADODB.Connection")
    Set cmd = CreateObject("ADODB.Recordset")

    Oracon.Open "Data Source=xcognosD;"

    Oracon.Execute "update xstore set last_update_date = sysdate where store_cd = '0000'"

    Oracon.Close

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