两种处理方法:
1、绑定到字段“合计”上,可以这样处理:
Private Sub Form_Load()
Dim ctls As Controls
Dim ctl As Control
Set ctls = Me.Controls
For Each ctl In ctls
If ctl.Name = "数学" Or ctl.Name = "物理" Or ctl.Name = "化学" Then
ctl.AfterUpdate = "=AllAfterUpdate()"
End If
Next
End Sub
Function AllAfterUpdate()
Me.合计.Value = Me.数学.Value + Me.物理.Value + Me.化学.Value
End Function
2、非绑定的,可以这样处理:
Private Sub Form_Load()
Dim ctls As Controls
Dim ctl As Control
Set ctls = Me.Controls
For Each ctl In ctls
If ctl.Name = "数学" Or ctl.Name = "物理" Or ctl.Name = "化学" Then
ctl.AfterUpdate = "=AllAfterUpdate()"
End If
Next
End Sub
Function AllAfterUpdate()
DoCmd.SetWarnings False
DoCmd.RunSQL "UPDATE 表1 SET 表1.合计 = [数学]+[物理]+[化学];"
End Function