|
Beforeinsert 需要用户按下一个键后才触发,所以用在这里不好. 其实current事件在新增时也触发的,可以通过判断primary key是否为空来辨别新纪录. 例子如下: (假设username是主毽,所有控件与字段同名)
Private Sub Form_Current()
Static bm As Variant
Dim rs As Recordset
Dim fld As Field
If IsNull(Me![username]) Then
Set rs = Me.RecordsetClone
rs.Bookmark = bm
For Each fld In rs.Fields
If fld.name <> "username" Then
Me.Controls(fld.name).Value = fld.Value
End If
Next fld
Else
Me![username].SetFocus '这样bookmark才会反映当前纪录,否则是上一纪录
bm = Me.Recordset.Bookmark
End If
End Sub |
|