从表单尝试时记录集不可更新,但如果仅加载子表单,则可以正常工作

Posted

技术标签:

【中文标题】从表单尝试时记录集不可更新,但如果仅加载子表单,则可以正常工作【英文标题】:Recordset is not updateable when try from form but work fine if only subform loaded 【发布时间】:2016-03-08 20:56:07 【问题描述】:

我有一个带有数据表子表单的表单。当我尝试加载主表单并更新子表单中的某些字段时,它给了我错误:(记录集不可更新)

但是当我自己加载子表单时它工作正常。我正在使用 Access 2007。

其中一个文件下的代码是:

Private Sub No_open_quality_issues_Click()
If (Me.No_open_quality_issues.Value = True) Then
    Me.No_open_quality_issues.Locked = True
End If
End Sub

当我从以下位置更改源记录源时,问题似乎发生了:

SELECT Production_Readiness.*
FROM Production_Readiness;

收件人:

SELECT DISTINCT Production_Readiness.*
FROM Production_Readiness
WHERE (((Production_Readiness.Material) Like '' & "*" Or (Production_Readiness.Material) Is Null) AND ((Production_Readiness.[All Engine Models]) Like '' & "*" Or (Production_Readiness.[All Engine Models]) Is Null) AND ((Production_Readiness.Commodities) Like '' & "*" Or (Production_Readiness.Commodities) Is Null) AND ((Production_Readiness.[Buyer Name]) Like '' & "*" Or (Production_Readiness.[Buyer Name]) Is Null) AND ((Production_Readiness.Vendor) Like '' & "*" Or (Production_Readiness.Vendor) Is Null) AND ((Production_Readiness.[Vendor Name]) Like '' & "*" Or (Production_Readiness.[Vendor Name]) Is Null) AND ((Production_Readiness.[MinOfStat-Rel Del Date     Next coming delivery])>=#5/16/1892# And (Production_Readiness.[MinOfStat-Rel Del Date     Next coming delivery])<=#3/15/2016#) AND ((Production_Readiness.[Buyer Badge])=FctUserID()) AND ((Production_Readiness.Status)<>'Processed'));

更具体地说,当我尝试在加载表单时使用此功能时会发生这种情况:

Private Function LoadHOQuery()

progComb_Filter = "Like '' & ""*"" Or (Production_Readiness.[All Engine Models]) Is Null"
partNoCmb_Filter = "Like '' & ""*"" Or (Production_Readiness.Material) Is Null"
commodCmb_Filter = "Like '' & ""*"" Or (Production_Readiness.Commodities) Is Null"
custCmb_Filter = "Like '' & ""*"" Or (Production_Readiness.[Buyer Name]) Is Null"
subCodeCmb_Filter = "Like '' & ""*"" Or (Production_Readiness.[Vendor]) Is Null"
subCmb_Filter = "Like '' & ""*"" Or (Production_Readiness.[Vendor Name]) Is Null"
startDateTxt_Filter = "5/16/1892"
endDateTxt_Filter = Date
Dim sqlCmd As String

Dim isFormLoades As Boolean
If (openCondition = "Buyer") Then
    isFormLoades = IsLoaded("Handoff_Frm")
    If (isFormLoades) Then
        sqlCmd = "SELECT DISTINCT Production_Readiness.* " & _
                 "FROM Production_Readiness " & _
                 "WHERE (((Production_Readiness.Material) " & partNoCmb_Filter & ") AND ((Production_Readiness.[All Engine Models]) " & progComb_Filter & ") AND " & _
                        "((Production_Readiness.Commodities) " & commodCmb_Filter & " ) AND ((Production_Readiness.[Buyer Name]) " & custCmb_Filter & " ) AND " & _
                        "((Production_Readiness.Vendor) " & subCodeCmb_Filter & ") AND ((Production_Readiness.[Vendor Name]) " & subCmb_Filter & ") AND " & _
                        "((Production_Readiness.[MinOfStat-Rel Del Date     Next coming delivery])>=#" & startDateTxt_Filter & "#) AND ((Production_Readiness.[MinOfStat-Rel Del Date     Next coming delivery])<=#" & endDateTxt_Filter & "#) And" & _
                        "(((Production_Readiness.[Buyer Badge])=FctUserID()) And ((Production_Readiness.[Status]) <>  'Processed') ) ); "

        'MsgBox sqlCmd


        Me.ManageHanOff.Form.RecordSource = sqlCmd
        Me.ManageHanOff.Form.Requery
     End If
 ElseIf (openCondition = "Manager") Then

 End If

结束函数

你能帮帮我吗?

谢谢

【问题讨论】:

主窗体上是否设置了父子关系? 是的,当子项上的某些字段满足某些约束时。父按钮启用/禁用取决于此值。 能否提供表单和子表单的控制源以及具有任何相关表关系的父/子字段? 你能给我更多的细节吗?此外,当我尝试在表单打开时导出表单和子表单的文档时,出现以下错误:应用程序定义或对象定义错误 我不需要文档,只需要位于主窗体和子窗体的属性窗格(在数据选项卡上)的控制源框中的代码。父/子也在属性窗格中。这是任何人都能够诊断问题的唯一方法。发布对您的问题的编辑,包括代码以及您从哪里提取代码。 【参考方案1】:

我发现了错误,它实际上是逻辑错误。 DISTINCT 中的问题。这就是为什么我不能更新的原因,因为它不止一个具有相同值的记录,而且访问不知道要更新哪个。

【讨论】:

以上是关于从表单尝试时记录集不可更新,但如果仅加载子表单,则可以正常工作的主要内容,如果未能解决你的问题,请参考以下文章

访问选择查询记录集不可更新

使用更新的参数集无法从 VB 关闭或刷新访问报表

在 MS Access 数据表子表单中导航和更新

如何在 Entity Framework 6.1 中仅加载子对象的某些字段?

Laravel 4 表单验证在更新表单上应该是唯一的,但如果是当前的则不是

带有连接的记录集不可更新 - 如何正确执行 VBA