|
以下代码大量参考了911网站的代码
Public Sub CopyRecord(frm As Form, strControlName As String)
On Error Resume Next
Static j As Boolean
Dim D, i As Long
Set D = CreateObject("Scripting.Dictionary")
Dim strSName() As String
strSName = Split(strControlName, ";")
If Not j And frm.NewRecord Then
frm.Recordset.MoveLast
j = True
For i = 0 To UBound(strSName) - 1
D.Add strSName(i), frm.Recordset(frm(strSName(i)).ControlSource).Value
Next i
DoCmd.GoToRecord , , acNewRec
For i = 0 To UBound(strSName) - 1
frm(strSName(i)).Value = D(strSName(i))
Next i
j = False
End If
Set D = Nothing
End Sub
用法,要在current事件中调用,注意是控件名,而不是字段名,并且最后的;号不要忘记加
Private Sub Form_Current()
CopyRecord Me, "控件1;控件2;控件3;"
End Sub
|
|