从 Excel 工作表更新 Access 2007 数据库中的记录时出现问题

发布于 2024-10-01 10:28:25 字数 1569 浏览 1 评论 0原文

我的 Excel 工作簿中有一个宏,用于更新与电子表格相关的 Access 数据库中的特定记录。

如果访问数据库关闭,一切正常。如果数据库打开并且用户正在编辑 Excel 电子表格相关的特定记录,就会出现问题。 我收到以下错误消息:

Error Number 2147467259: 
The database has been paced in a state by user 'ADMIN' on
'LAPTOP' that prevents it from being opened or locked.

我已将数据库表单的记录锁设置为“无记录锁”,但这没有帮助。

非常感谢任何建议或帮助。

干杯 诺埃尔

Public Sub updateAccessRecord()
On Error GoTo ProcError
Dim subFuncName As String
subFuncName = "updateAccessRecord"

Dim conn As ADODB.Connection
Dim cmd As ADODB.Command
Dim rst As ADODB.Recordset

Dim dbName As String
Dim dbPath As String
Dim strCon As String
Dim recID As Long
Dim fieldVal As Double
Dim strSQL As String

fieldVal = Worksheets("House Claim").Cells(593, 10).Value
dbName = "claim-db.mdb"
dbPath = ThisWorkbook.Path & "\..\..\..\..\"
dbPath = dbPath & "\" & dbName

strSQL = "UPDATE tblInsClaimDet SET propSet=" & fieldVal & " WHERE ID=" & recID & ""

   Set conn = New ADODB.Connection
   With conn
    .ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
       "Data Source=" & dbPath
       .Open
   End With
   Set cmd = New ADODB.Command
   With cmd
      .ActiveConnection = conn
      .CommandText = strSQL
   End With
   Set rst = cmd.Execute
   Set rst = Nothing
   conn.Close
   Set conn = Nothing

ExitProc:

   Exit Sub

ProcError:

   MsgBox "Error " & Err.Number & ": " & Err.Description, _
         vbCritical, "Error in procedure in " & subFuncName
   Resume ExitProc
End Sub 

I have a macro in my excel workbook that updates a specific record in the access database related to the spreadsheet.

All works fine if the access database is closed. Problems arise if the database is open and a user is editing the specific record that the excel spreadsheet relates to.`
I get the following Error Message:

Error Number 2147467259: 
The database has been paced in a state by user 'ADMIN' on
'LAPTOP' that prevents it from being opened or locked.

I have set the database form's Record Locks to 'No Record Locks' but this hasn't helped.

Any advice or help is greatly appreciated.

Cheers
Noel

Public Sub updateAccessRecord()
On Error GoTo ProcError
Dim subFuncName As String
subFuncName = "updateAccessRecord"

Dim conn As ADODB.Connection
Dim cmd As ADODB.Command
Dim rst As ADODB.Recordset

Dim dbName As String
Dim dbPath As String
Dim strCon As String
Dim recID As Long
Dim fieldVal As Double
Dim strSQL As String

fieldVal = Worksheets("House Claim").Cells(593, 10).Value
dbName = "claim-db.mdb"
dbPath = ThisWorkbook.Path & "\..\..\..\..\"
dbPath = dbPath & "\" & dbName

strSQL = "UPDATE tblInsClaimDet SET propSet=" & fieldVal & " WHERE ID=" & recID & ""

   Set conn = New ADODB.Connection
   With conn
    .ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
       "Data Source=" & dbPath
       .Open
   End With
   Set cmd = New ADODB.Command
   With cmd
      .ActiveConnection = conn
      .CommandText = strSQL
   End With
   Set rst = cmd.Execute
   Set rst = Nothing
   conn.Close
   Set conn = Nothing

ExitProc:

   Exit Sub

ProcError:

   MsgBox "Error " & Err.Number & ": " & Err.Description, _
         vbCritical, "Error in procedure in " & subFuncName
   Resume ExitProc
End Sub 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

同尘 2024-10-08 10:28:25

看来你没有把数据库分成前端和后端。如果你这样做了,问题就会消失。 Ctrl+S不是保存一条记录,而是Shift+Enter,它是保存一个数据库对象,所以看起来有把数据库扔到设计或开发状态的效果。

It seems that you have not split the database into a front-end and a back-end. The problem goes away if you do. Ctrl+S is not for saving a record, that is Shift+Enter, it is for saving a database object, and so it seems it has the effect of throwing the database into design or development state.

岁吢 2024-10-08 10:28:25

宏观方面;您是否尝试过以只读方式打开连接?即使您的 Access 用户没有锁定记录,他也对该记录具有“读锁”,从而防止 Excel 进行独占锁定。我想如果两个用户都只尝试读取访问,那么应该没问题;但如果其中任何一个正在执行读/写操作,那么它将失败。

在您的访问表单上,您还应该具有:

Me.AllowAdditions = True

Me.AllowDeletions = False

Me.AllowEdits = False

On the macro side; have you tried opening your connection as read-only? Even though your Access user is not locking the record, he has a "read lock" on the record, thereby preventing an exclusive lock by excel. I'm thinking that if both users are only attempting only read access, you should be Ok; but if either one is doing read/write, then it will fail.

On your access form, you should also have:

Me.AllowAdditions = True

Me.AllowDeletions = False

Me.AllowEdits = False

挽你眉间 2024-10-08 10:28:25

问题可能不在您的代码中。错误:

数据库已处于状态

表示数据库已以独占模式打开。您应该检查打开数据库的方式。

The problem is probably not in your code. The error:

The database has been paced in a state by

Indicates that the database has been opened in an exclusive mode. You should check how you are opening the database.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文