3027“无法更新。数据库或对象是只读的。”从excel使用make table之后

时间:2016-11-04 11:00:15

标签: excel excel-vba ms-access vba

我可以通过excel访问我的数据库,当我第二次尝试访问它时会出现问题。我似乎在我身后留下一些东西,但我不明白是什么。

Dim con As ADODB.Connection
Dim cmd As ADODB.Command
Dim strInput As String

Set con = New ADODB.Connection
Set cmd = New ADODB.Command
strInput = Sheets("base_pivot").Range("I4").Value
'I get the input for the parameter from my sheet base_pivot on the cell I4

With con
    .Provider = "Microsoft.ACE.OLEDB.12.0"
    .Open "C:\cmo_accounting\CMO_accounting.mdb"
End With

With cmd
    .ActiveConnection = con
    .CommandText = "mk_edu_ana_invoices"
    .CommandType = adCmdStoredProc

    .Parameters.Append cmd.CreateParameter("[input_code_ana]", adChar, adParamInput, 5)
    .Parameters("[input_code_ana]") = strInput
End With

cmd.Execute

con.Close

Set cmd = Nothing
Set prm = Nothing
Set con = Nothing

这是我第一次使用它时,它会在我重新打开excel文件后再次运行。当excel关闭时,似乎连接已关闭。

1 个答案:

答案 0 :(得分:0)

最后我找到了问题的答案。它链接到我的excel文件中的查询。当我从访问文件刷新数据时,它会打开访问文件。我以前从未遇到过这样的问题,所以我真的认为这是我的vba代码。我必须做的是将连接字符串从“share deny read”更改为“share deny none”。

感谢大家的帮助。