为什么在保存记录时出现 运行-time error '2759'?访问 2010
Why do I get run-time error '2759' when saving the record? access 2010
使用 Access 2010,我有一个 Purchase_Orders
的表单,其中 status
根据子表单中的 Items
是否已交付而变化,并且,它也受日期影响。
Private Sub Form_AfterUpdate()
Dim rs As Recordset
Dim db As Database
Dim var_Delivered As String
var_Delivered = "SELECT Count(*) AS d_Count" & _
" FROM Items" & _
" WHERE PO_ID =" & Me.PO_ID.Value & _
" AND Supplier_Dnote_ID IS Null" & _
" AND Delivered_Without_Dnote =0;"
Set db = CurrentDb
Set rs = db.OpenRecordset(var_Delivered, dbOpenDynaset)
'MsgBox rs!d_Count
If rs!d_Count > 0 Then
If Me.Supply_date < Date Then
Me.Status = "Overdue"
Else
Me.Status = "Submitted"
End If
Else
Me.Status = "Delivered"
End If
db.Close
Set db = Nothing
Set rs = Nothing
End Sub
本运行s after_update的Purchase_Orders
。我有一个 save_close
按钮,它使用以下代码并且没有 return 错误:
If Me.Dirty = True Then
DoCmd.Close acForm, "Purchase_Orders", acSaveYes
Else
DoCmd.Close acForm, "Purchase_Orders", acSaveNo
End If
但是,我还有一个 Save
按钮不会关闭表单。这是我得到 运行 时间错误 2759 的地方:您尝试在对象上调用的方法失败。调试突出显示 saverecord 行。
Private Sub SaveOnlyBtn_Click()
If Me.Dirty = True Then
docmd.RunCommand acCmdSaveRecord
End If
End Sub
如果我注释掉状态代码并使用保存按钮,记录会保存得很好,没有任何错误。为什么会出现此错误?我完全被难住了,在线搜索错误也没有帮助我。
所以我发现当我把代码放在"on dirty"事件中时并没有发生错误,这让我意识到我并不需要一定要运行之后的代码仅当特定字段更改时,表单才会更新。所以我将代码更改为 public 代码,并在 supply date
、delivered_without_dnote
或 supplier_Invoice_ID
更改时调用它。
public 代码是:
Public Sub delivered_status()
On Error GoTo errTrap1
If Forms!Purchase_Orders_Ex.Form!Status = "Cancelled" Then
Exit Sub
Else
DoCmd.RunCommand acCmdSaveRecord
Dim rs As Recordset
Dim db As Database
Dim var_Delivered As String
var_Delivered = "SELECT Count(*) AS d_Count" & _
" FROM Items" & _
" WHERE PO_ID =" & Forms!Purchase_Orders_Ex.Form!PO_ID.Value & _
" AND Supplier_Dnote_ID IS Null" & _
" AND Delivered_Without_Dnote =0;"
Set db = CurrentDb
Set rs = db.OpenRecordset(var_Delivered, dbOpenDynaset)
'MsgBox "Outstanding Items: " & rs!d_Count
If rs!d_Count > 0 Then
If Forms!Purchase_Orders_Ex.Form!Supply_date < Date Then
Forms!Purchase_Orders_Ex.Form!Status = "Overdue"
Else
Forms!Purchase_Orders_Ex.Form!Status = "Submitted"
End If
Else
Forms!Purchase_Orders_Ex.Form!Status = "Delivered"
End If
rs.Close
Set db = Nothing
Set rs = Nothing
End If
errTrap1:
Select Case Err.Number
Case 3314 'form not complete and other required fields are empty
Exit Sub
Case Else
If Err.Number > 0 Then
MsgBox Err.Number & ": " & Err.Description
End If
End Select
End Sub
现在,当我使用 save_close
或 Save_Only
时,我没有收到错误 2759。我不完全理解我的原始方法的哪一部分导致了错误,但它不再发生这种方法。
我刚遇到这个问题,将代码从 Form_AfterUpdate 中移出也为我解决了这个问题。
(模糊地)有趣的是,有问题的代码在本地运行良好,但在部署到客户端时却无法运行。我尝试只导入修改后的表单而不是替换整个访问应用程序,但我仍然遇到同样的问题。我还将后端数据库从服务器复制回我的开发机器,但仍然没有在本地解决问题。最重要的是,我做了无穷无尽的 compact/repair 和 decompile/compile。
最后我的结论是,这是 Access 黑盒产生的另一个奇怪问题,而不是特定代码的问题。
使用 Access 2010,我有一个 Purchase_Orders
的表单,其中 status
根据子表单中的 Items
是否已交付而变化,并且,它也受日期影响。
Private Sub Form_AfterUpdate()
Dim rs As Recordset
Dim db As Database
Dim var_Delivered As String
var_Delivered = "SELECT Count(*) AS d_Count" & _
" FROM Items" & _
" WHERE PO_ID =" & Me.PO_ID.Value & _
" AND Supplier_Dnote_ID IS Null" & _
" AND Delivered_Without_Dnote =0;"
Set db = CurrentDb
Set rs = db.OpenRecordset(var_Delivered, dbOpenDynaset)
'MsgBox rs!d_Count
If rs!d_Count > 0 Then
If Me.Supply_date < Date Then
Me.Status = "Overdue"
Else
Me.Status = "Submitted"
End If
Else
Me.Status = "Delivered"
End If
db.Close
Set db = Nothing
Set rs = Nothing
End Sub
本运行s after_update的Purchase_Orders
。我有一个 save_close
按钮,它使用以下代码并且没有 return 错误:
If Me.Dirty = True Then
DoCmd.Close acForm, "Purchase_Orders", acSaveYes
Else
DoCmd.Close acForm, "Purchase_Orders", acSaveNo
End If
但是,我还有一个 Save
按钮不会关闭表单。这是我得到 运行 时间错误 2759 的地方:您尝试在对象上调用的方法失败。调试突出显示 saverecord 行。
Private Sub SaveOnlyBtn_Click()
If Me.Dirty = True Then
docmd.RunCommand acCmdSaveRecord
End If
End Sub
如果我注释掉状态代码并使用保存按钮,记录会保存得很好,没有任何错误。为什么会出现此错误?我完全被难住了,在线搜索错误也没有帮助我。
所以我发现当我把代码放在"on dirty"事件中时并没有发生错误,这让我意识到我并不需要一定要运行之后的代码仅当特定字段更改时,表单才会更新。所以我将代码更改为 public 代码,并在 supply date
、delivered_without_dnote
或 supplier_Invoice_ID
更改时调用它。
public 代码是:
Public Sub delivered_status()
On Error GoTo errTrap1
If Forms!Purchase_Orders_Ex.Form!Status = "Cancelled" Then
Exit Sub
Else
DoCmd.RunCommand acCmdSaveRecord
Dim rs As Recordset
Dim db As Database
Dim var_Delivered As String
var_Delivered = "SELECT Count(*) AS d_Count" & _
" FROM Items" & _
" WHERE PO_ID =" & Forms!Purchase_Orders_Ex.Form!PO_ID.Value & _
" AND Supplier_Dnote_ID IS Null" & _
" AND Delivered_Without_Dnote =0;"
Set db = CurrentDb
Set rs = db.OpenRecordset(var_Delivered, dbOpenDynaset)
'MsgBox "Outstanding Items: " & rs!d_Count
If rs!d_Count > 0 Then
If Forms!Purchase_Orders_Ex.Form!Supply_date < Date Then
Forms!Purchase_Orders_Ex.Form!Status = "Overdue"
Else
Forms!Purchase_Orders_Ex.Form!Status = "Submitted"
End If
Else
Forms!Purchase_Orders_Ex.Form!Status = "Delivered"
End If
rs.Close
Set db = Nothing
Set rs = Nothing
End If
errTrap1:
Select Case Err.Number
Case 3314 'form not complete and other required fields are empty
Exit Sub
Case Else
If Err.Number > 0 Then
MsgBox Err.Number & ": " & Err.Description
End If
End Select
End Sub
现在,当我使用 save_close
或 Save_Only
时,我没有收到错误 2759。我不完全理解我的原始方法的哪一部分导致了错误,但它不再发生这种方法。
我刚遇到这个问题,将代码从 Form_AfterUpdate 中移出也为我解决了这个问题。
(模糊地)有趣的是,有问题的代码在本地运行良好,但在部署到客户端时却无法运行。我尝试只导入修改后的表单而不是替换整个访问应用程序,但我仍然遇到同样的问题。我还将后端数据库从服务器复制回我的开发机器,但仍然没有在本地解决问题。最重要的是,我做了无穷无尽的 compact/repair 和 decompile/compile。
最后我的结论是,这是 Access 黑盒产生的另一个奇怪问题,而不是特定代码的问题。