OFFICE 2019 ACCESS遍历窗口文本框和组合框
If MsgBox("您确定要修改当权记录内容吗?", vbYesNo, "提醒") = vbYes Then
Dim OldStr As String
Dim NewStr As String
Dim Ctl As Access.Control
'' Dim Ctl As Access.TextBox
'' Dim CtlCombo As Access.ComboBox
' On Error Resume Next
For Each Ctl In Me.Form.Controls '遍历控件汇总新旧数据进行对比,若一致则表明未修改,则不用进行后续修改程序
If Ctl.Name <> "父阶物料" Then '因为父阶物料属临时文本框,数据表中并无该字段,故不用考虑对吧
If Ctl.ControlType = 109 or Ctl.ControlType = 111 Then '109代表文本框,111代表组合框
If Nz(OldStr, "") = "" Then
OldStr = Ctl.Value
NewStr = DLookup(Ctl.Name, "My_ProductTable", "产品代码='" & Me.产品代码 & "'")
Else
OldStr = OldStr & "|" & Ctl.Value
NewStr = NewStr & "|" & DLookup(Ctl.Name, "My_ProductTable", "产品代码='" & Me.产品代码 & "'")
End If
End If
End If
Next
' For Each CtlCombo In Me.Form.Controls
' If Nz(OldStr, "") = "" Then
' OldStr = CtlCombo.Value
' NewStr = DLookup(CtlCombo.Name, "My_ProductTable", "产品代码='" & Me.产品代码 & "'")
' Else
' OldStr = OldStr & "|" & CtlCombo.Value
' NewStr = NewStr & "|" & DLookup(CtlCombo.Name, "My_ProductTable", "产品代码='" & Me.产品代码 & "'")
' End If
' Next
Debug.Print OldStr
Debug.Print NewStr
If OldStr = NewStr Then MsgBox "您并未修改当前记录,请确认!", , "提醒": Exit Sub
DoCmd.OpenForm "frmMy_KeyPassWord", OpenArgs:="ChangeProduct" & "|" & Me.产品代码: Exit Sub
Else
Exit Sub
End If