【问题标题】:3027 "Cannot update. Database or object is read-only." after using make table from excel3027 “无法更新。数据库或对象是只读的。”使用 excel 中的制作表后
【发布时间】:2016-11-04 11:00:15
【问题描述】:

我可以通过 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时似乎连接已关闭。

【问题讨论】:

  • 我发现了几件事 - 但不确定是否会有所作为。你在哪里定义了strPath? (使用option explicit 可以避免这些问题)。 Range("I4:I4") 也可以是 .Range("I4")
  • 嘿,我对 strPath 进行了更改,我将字符串放在那里,这样每个人都更清楚。我将对范围 I4 进行更改。谢谢!
  • 这个宏(子或函数)在哪里,它是如何触发的?工作簿的其他地方是否有另一个数据库连接?

标签: excel ms-access vba


【解决方案1】:

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

感谢大家的帮助。

【讨论】:

    猜你喜欢
    • 2014-11-28
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 2017-07-28
    • 1970-01-01
    • 1970-01-01
    • 2019-09-11
    • 1970-01-01
    相关资源
    最近更新 更多