그래서 저는 VBA 액세스에 익숙하지 않고 방금 코드에 큰 문제가 발생했습니다. 설명해 드리겠습니다. 현재 레코드의 데이터를로드하고 사용자가 레코드를 편집 할 수있는 폼이 있습니다. 현재 변경된 데이터가 데이터베이스에서 제대로 업데이트되도록 저장 버튼을 만들고 있습니다. 내가 가진 것은 텍스트 상자의 데이터가 레코드 세트의 데이터와 동일한 지 확인하는 검사입니다. 문제는 데이터가 데이터베이스에서 null 인 경우 텍스트 상자에 "업데이트 된 그룹"과 같은 텍스트 상자가있는 것처럼 데이터가 실행되는 것처럼 실행됩니다. 나에게 이것이 약간의 감독과 다소 실망 스럽다. 내 질문은 누구든지이 문제에 대한 해결 방법을 알고 있습니까?VBA : 현재 데이터를 기반으로 레코드 세트 업데이트
미리 감사드립니다. 여기
는 대답 : 만약 RstRecSet ("그룹 이름") 값 & "" <> 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
코드가 사용자가 설명하는 것과 일치하지 않는 것 같습니다. 당신이 확인한 것처럼 보입니다. "다른 무엇입니까?" 그렇다면 실제로 레코드 편집 외에도 새 레코드를 추가하십시오. 나는 당신이 실제로 무엇을 요구하고 있는지 확신하지 못한다. – enderland
감사 테이블에 대해서만 추가 레코드에주의를 기울이지 마십시오. 너와 같은 작품들은 그것을 분명하게했다. "다른 것은 다른 것입니까? 그때 다른 것을 바꾸십시오". 문제는 "KnownAs"가 "아무 것도 다르지 않은가?"라는 방아쇠를 당기지 않은 기록에 아무것도 없다는 것을 말합니다. 성명 (나는 그것이 null로 생각하기 때문에), 그것은 단지 그것이라고 가정합니다. – SaladSnake
null 값은 비교 중에 이상한 결과를 초래할 수 있으므로 레코드 세트 필드가 Null인지 확인해야합니다. 즉 'RstRecSet ("GroupName") 인 경우 Value & ""<> txtGroupNameEdit.Value & "".... –