【发布时间】:2014-04-04 05:17:38
【问题描述】:
我在 MS Access 2010 中有一堆表单。它们都是绑定的表单,但我欺骗了它们,只在单击 btnSave 时才保存。
主要问题是我有很多代码对于某些事件中的每个表单都是相同的,例如form_beforeUpdate() 或form_afterUpdate() 或form_Load()。一个例子:
Private Sub btnSave_Click()
'Check first that all fields have been filled
If CheckAllFields = True Then
Exit Sub
End If
TempSaveRecord = True
Me.Dirty = False 'this will make an attempt of form_Update()
Form_Load 'After Saving we restart the data
End Sub
Private Sub Form_BeforeUpdate(Cancel As Integer)
If TempSaveRecord = False Then
Me.Undo
Exit Sub
End If
End Sub
CheckAllFields只是一个例程,检查所有必填字段是否不是null:
Private Function CheckAllFields() As Boolean
Dim Ctrl As Control
CheckAllFields = False
'Check for unfilled fields
For Each Ctrl In Me.Controls
If Ctrl.Tag = "required" And IsNull(Ctrl) Then
MsgBox "The field " & Ctrl.Name & " has not been filled."
CheckAllFields = True
Exit For
End If
Next Ctrl
End Function
我想在一个模块中完成所有这些工作,但当时我找不到获取表单实际实例的方法。任何帮助将不胜感激。
谢谢
【问题讨论】: