Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ms access VBA:基于当前数据更新记录集_Ms Access_Vba - Fatal编程技术网

Ms access VBA:基于当前数据更新记录集

Ms access VBA:基于当前数据更新记录集,ms-access,vba,Ms Access,Vba,所以我对vba访问还不熟悉,只是在代码方面遇到了一个大问题。让我解释一下,我有一个表单,它从当前记录加载数据并允许用户编辑它。目前,我正在创建“保存”按钮,以便在数据库中正确更新已更改的数据。我所做的是检查以确保文本框中的数据与记录集中的数据相等。问题是,如果数据库中的数据为空,则即使文本框中有“更新组”,它也会像与文本框中的数据相等一样运行。对我来说,这有点疏忽,有点令人失望。我的问题是,有人知道这个问题的解决方法吗 提前感谢您提供的任何信息 答案如下:如果RstRecSet(“GroupNa

所以我对vba访问还不熟悉,只是在代码方面遇到了一个大问题。让我解释一下,我有一个表单,它从当前记录加载数据并允许用户编辑它。目前,我正在创建“保存”按钮,以便在数据库中正确更新已更改的数据。我所做的是检查以确保文本框中的数据与记录集中的数据相等。问题是,如果数据库中的数据为空,则即使文本框中有“更新组”,它也会像与文本框中的数据相等一样运行。对我来说,这有点疏忽,有点令人失望。我的问题是,有人知道这个问题的解决方法吗

提前感谢您提供的任何信息

答案如下:如果RstRecSet(“GroupName”).Value&“txtGroupNameEdit.Value&”-Wayne

这是我的密码:

    Dim searchGroup As String
Dim db As DAO.Database
Dim RstRecSet As DAO.Recordset
Dim Rst As DAO.Recordset
Set db = CurrentDb
searchGroup = txtGroupNrEdit
Set RstRecSet = db.OpenRecordset("Select * from tblGroupHeader Where groupNum like '*" & searchGroup & "*';", dbOpenDynaset)
Set Rst = db.OpenRecordset("Select * from tblAuditTable;", dbOpenDynaset)

If RstRecSet("GroupName").Value <> txtGroupNameEdit.Value Or RstRecSet("PlanStartDate").Value <> txtStartDateEdit.Value _
Or RstRecSet("CanDate").Value <> txtCanDateEdit.Value Or RstRecSet("ClerkID").Value <> txtClerkIDEdit.Value _
Or RstRecSet("PopulationType").Value <> txtGroupTypeEdit.Value Or RstRecSet("COC").Value <> chkCOCEdit.Value _
Or RstRecSet("CDHFinancialPartner").Value <> cmbCDHEdit.Value Or RstRecSet("CDHProdOptions").Value <> chkCDHEdit.Value _
Or RstRecSet("MemberLevelBenefits").Value <> chkMembBeneEdit.Value Or RstRecSet("Comments").Value <> txtCommentsEdit.Value _
Or RstRecSet("AlsoKnownAs").Value <> txtKnownEdit.Value Or RstRecSet("BCBS").Value <> chkBCBSEdit.Value _
Or RstRecSet("Other").Value <> chkOtherEdit.Value Then
    RstRecSet.Edit
    Rst.AddNew
        If RstRecSet("AlsoKnownAs").Value <> txtKnownEdit.Value Then
        Rst("GroupName").Value = txtGroupNameEdit.Value
        Rst("GroupNum").Value = txtGroupNrEdit.Value
        RstRecSet("AlsoKnownAs").Value = txtKnownEdit.Value
        Rst("AlsoKnownAs").Value = RstRecSet("AlsoKnownAs")
        Rst("DateChanged").Value = Date
        End If
        If RstRecSet("PlanStartDate").Value <> txtStartDateEdit.Value Then
        Rst("GroupName").Value = txtGroupNameEdit.Value
        Rst("GroupNum").Value = txtGroupNrEdit.Value
        RstRecSet("PlanStartDate").Value = txtStartDateEdit.Value
        Rst("PlanStartDate").Value = RstRecSet("PlanStartDate")
        Rst("DateChanged").Value = Date
        End If
        If RstRecSet("CanDate").Value <> txtCanDateEdit.Value Then
        Rst("GroupName").Value = txtGroupNameEdit.Value
        Rst("GroupNum").Value = txtGroupNrEdit.Value
        RstRecSet("CanDate").Value = txtCanDateEdit.Value
        Rst("CanDate").Value = RstRecSet("CanDate")
        Rst("DateChanged").Value = Date
        End If
        If RstRecSet("PopulationType").Value <> txtGroupTypeEdit.Value Then
        Rst("GroupName").Value = txtGroupNameEdit.Value
        Rst("GroupNum").Value = txtGroupNrEdit.Value
        RstRecSet("PopulationType").Value = txtGroupTypeEdit.Value
        Rst("PopulationType").Value = RstRecSet("PopulationType")
        Rst("DateChanged").Value = Date
        End If
        If RstRecSet("CDHFinancialPartner").Value <> cmbCDHEdit.Value Then
        Rst("GroupName").Value = txtGroupNameEdit.Value
        Rst("GroupNum").Value = txtGroupNrEdit.Value
        RstRecSet("CDHFinancialPartner").Value = cmbCDHEdit.Value
        Rst("CDHFinancialPartner").Value = RstRecSet("CDHFinancialPartner")
        Rst("DateChanged").Value = Date
        End If
        If RstRecSet("MemberLevelBenefits").Value <> chkMembBeneEdit.Value Then
        Rst("GroupName").Value = txtGroupNameEdit.Value
        Rst("GroupNum").Value = txtGroupNrEdit.Value
        RstRecSet("MemberLevelBenefits").Value = chkMembBeneEdit.Value
        Rst("MemberLevelBenefits").Value = RstRecSet("MemberLevelBenefits")
        Rst("DateChanged").Value = Date
        End If
        If RstRecSet("Other").Value <> chkOtherEdit.Value Then
        Rst("GroupName").Value = txtGroupNameEdit.Value
        Rst("GroupNum").Value = txtGroupNrEdit.Value
        RstRecSet("Other").Value = chkOtherEdit.Value
        Rst("Other").Value = RstRecSet("Other")
        Rst("DateChanged").Value = Date
        End If
        If RstRecSet("ClerkID").Value <> txtClerkIDEdit.Value Then
        Rst("GroupName").Value = txtGroupNameEdit.Value
        Rst("GroupNum").Value = txtGroupNrEdit.Value
        RstRecSet("ClerkID").Value = txtClerkIDEdit.Value
        Rst("ClerkID").Value = RstRecSet("ClerkID")
        Rst("DateChanged").Value = Date
        End If
        If RstRecSet("COC").Value <> chkCOCEdit.Value Then
        Rst("GroupName").Value = txtGroupNameEdit.Value
        Rst("GroupNum").Value = txtGroupNrEdit.Value
        RstRecSet("COC").Value = chkCOCEdit.Value
        Rst("COC").Value = RstRecSet("COC")
        Rst("DateChanged").Value = Date
        End If
        If RstRecSet("CDHProdOptions").Value <> chkCDHEdit.Value Then
        Rst("GroupName").Value = txtGroupNameEdit.Value
        Rst("GroupNum").Value = txtGroupNrEdit.Value
        RstRecSet("CDHProdOptions").Value = chkCDHEdit.Value
        Rst("CDHProdOptions").Value = RstRecSet("CDHProdOptions")
        Rst("DateChanged").Value = Date
        End If
        If RstRecSet("Comments").Value <> txtCommentsEdit.Value Then
        Rst("GroupName").Value = txtGroupNameEdit.Value
        Rst("GroupNum").Value = txtGroupNrEdit.Value
        RstRecSet("Comments").Value = txtCommentsEdit.Value
        Rst("SpecialConsideration").Value = RstRecSet("Comments")
        Rst("DateChanged").Value = Date
        End If
        If RstRecSet("BCBS").Value <> chkBCBSEdit.Value Then
        Rst("GroupName").Value = txtGroupNameEdit.Value
        Rst("GroupNum").Value = txtGroupNrEdit.Value
        RstRecSet("BCBS").Value = chkBCBSEdit.Value
        Rst("BCBS").Value = RstRecSet("BCBS")
        Rst("DateChanged").Value = Date
        End If
        If RstRecSet("GroupName").Value <> txtGroupNameEdit.Value Then
        Rst("GroupName").Value = txtGroupNameEdit.Value
        Rst("GroupNum").Value = txtGroupNrEdit.Value
        RstRecSet("GroupName").Value = txtGroupNameEdit.Value
        Rst("GroupName").Value = RstRecSet("GroupName")
        Rst("DateChanged").Value = Date
        End If
    Rst.Update
    RstRecSet.Update
End If
Dim searchGroup作为字符串
Dim数据库作为DAO.Database
将RstRecSet设置为DAO.Recordset
将Rst设置为DAO.Recordset
Set db=CurrentDb
searchGroup=txtGroupNrEdit
Set RstRecSet=db.OpenRecordset(“从tblGroupHeader中选择*,其中groupNum类似于“*”&searchGroup&“*”;”,dbOpenDynaset)
Set Rst=db.OpenRecordset(“从tblAuditTable;中选择*”,dbOpenDynaset)
如果RstRecSet(“GroupName”).Value txtGroupNameEdit.Value或RstRecSet(“PlanStartDate”).Value txtStartDateEdit.Value_
或RstRecSet(“CanDate”).Value txtCanDateEdit.Value或RstRecSet(“ClerkID”).Value txtClerkIDEdit.Value_
或RstRecSet(“PopulationType”).Value txtGroupTypeEdit.Value或RstRecSet(“COC”).Value chkProcedit.Value_
或RstRecSet(“CDHFinancialPartner”)。值cmbCDHEdit.Value或RstRecSet(“CDHProdOptions”)。值chkCDHEdit.Value_
或RstRecSet(“MemberLevelBenefits”).Value chkmembbeeneedit.Value或RstRecSet(“Comments”).Value txtccommentsedit.Value_
或RstRecSet(“AlsoKnownAs”).Value txtnownedit.Value或RstRecSet(“BCBS”).Value chkbcbedit.Value_
或RstRecSet(“其他”)。值chkOtherEdit.Value然后
RstRecSet.Edit
Rst.AddNew
如果RstRecSet(“AlsoKnownAs”).Value txtnownedit.Value,则
Rst(“GroupName”).Value=txtGroupNameEdit.Value
Rst(“GroupNum”).Value=txtGroupnEdit.Value
RstRecSet(“AlsoKnownAs”).Value=txtnownedit.Value
Rst(“AlsoKnownAs”)。值=RstRecSet(“AlsoKnownAs”)
Rst(“日期更改”)。值=日期
如果结束
如果RstRecSet(“PlanStartDate”).Value txtStartDateEdit.Value,则
Rst(“GroupName”).Value=txtGroupNameEdit.Value
Rst(“GroupNum”).Value=txtGroupnEdit.Value
RstRecSet(“PlanStartDate”).Value=txtStartDateEdit.Value
Rst(“PlanStartDate”)。值=RstRecSet(“PlanStartDate”)
Rst(“日期更改”)。值=日期
如果结束
如果RstRecSet(“CanDate”).Value txtCanDateEdit.Value,则
Rst(“GroupName”).Value=txtGroupNameEdit.Value
Rst(“GroupNum”).Value=txtGroupnEdit.Value
RstRecSet(“CanDate”).Value=txtCanDateEdit.Value
Rst(“CanDate”)。值=RstRecSet(“CanDate”)
Rst(“日期更改”)。值=日期
如果结束
如果RstRecSet(“PopulationType”).Value txtGroupTypeEdit.Value,则
Rst(“GroupName”).Value=txtGroupNameEdit.Value
Rst(“GroupNum”).Value=txtGroupnEdit.Value
RstRecSet(“PopulationType”).Value=txtGroupTypeEdit.Value
Rst(“填充类型”)。值=RstRecSet(“填充类型”)
Rst(“日期更改”)。值=日期
如果结束
如果RstRecSet(“CDHFinancialPartner”).值CMBHEDIT.值,则
Rst(“GroupName”).Value=txtGroupNameEdit.Value
Rst(“GroupNum”).Value=txtGroupnEdit.Value
RstRecSet(“CDHFinancialPartner”).Value=cmbCDHEdit.Value
Rst(“CDHFinancialPartner”)。值=RstRecSet(“CDHFinancialPartner”)
Rst(“日期更改”)。值=日期
如果结束
如果RstRecSet(“MemberLevelBenefits”).Value chkmembbeeneedit.Value,则
Rst(“GroupName”).Value=txtGroupNameEdit.Value
Rst(“GroupNum”).Value=txtGroupnEdit.Value
RstRecSet(“MemberLevelBenefits”).Value=chkmembbeeneedit.Value
Rst(“MemberLevelBenefits”)。值=RstRecSet(“MemberLevelBenefits”)
Rst(“日期更改”)。值=日期
如果结束
如果RstRecSet(“其他”)值chkOtherEdit.Value,则
Rst(“GroupName”).Value=txtGroupNameEdit.Value
Rst(“GroupNum”).Value=txtGroupnEdit.Value
RstRecSet(“其他”).Value=chkOtherEdit.Value
Rst(“其他”)。值=RstRecSet(“其他”)
Rst(“日期更改”)。值=日期
如果结束
如果RstRecSet(“ClerkID”).Value txtClerkIDEdit.Value,则
Rst(“GroupName”).Value=txtGroupNameEdit.Value
Rst(“GroupNum”).Value=txtGroupnEdit.Value
RstRecSet(“ClerkID”).Value=txtClerkIDEdit.Value
Rst(“ClerkID”)。值=RstRecSet(“ClerkID”)
Rst(“日期更改”)。值=日期
如果结束
如果RstRecSet(“COC”).值chkCOCEdit.值,则
Rst(“GroupName”).Value=txtGroupNameEdit.Value
Rst(“GroupNum”).Value=txtGroupnEdit.Value
RstRecSet(“COC”).Value=chkCOCEdit.Value
Rst(“COC”)。值=RstRecSet(“COC”)
Rst(“日期更改”)。值=日期
如果结束
如果RstRecSet(“CDHProdOptions”).Value chkCDHEdit.Value,则
Rst(“GroupName”).Value=txtGroupNameEdit.Value
Rst(“GroupNum”).Value=txtGroupnEdit.Value
RstRecSet(“CDHProdOptions”).Value=chkCDHEdit.Value
Rst(“CDHProdOptions”)。值=RstRecSet(“CDHProdOptions”)
Rst(“日期更改”)。值=日期
如果结束
如果RstRecSet(“Comments”).Value txtccommentsedit.Value,则
Rst(“GroupName”).Value=txtGroupNameEdit.Value
Rst(“GroupNum”).Value=txtGroupnEdit.Value
RstRecSet(“Comments”).Value=txtccommentsedit.Value
Rst(“特殊考虑”)。值=RstRecSet(“评论”)
Rst(“日期更改”)。值=日期
如果结束
如果RstRecSet(“BCBS”)。值ch
If RstRecSet("GroupName").Value & "" <> txtGroupNameEdit.Value & "" Or ...