|
我常用的方法:
1.如果是输入,使用ctr+' 获取上条记录同字段的值到新记录
2.在afterupdate事件中输入代码,循环需要设置上条记录默认值的字段,设置 文本框.defaultvalue="""" & 文本框.value & """"
3.使用微软的方法.
在窗体的oncurrent(成为当前)事件中加入 =AutoFillNewRecord([Forms]![Customers])
Function AutoFillNewRecord(F As Form)
Dim RS As Recordset, C As Control
Dim FillFields As String, FillAllFields As Integer
On Error Resume Next
' Exit if not on the new record.
If Not F.NewRecord Then Exit Function
' Goto the last record of the form recordset (to autofill form).
Set RS = F.RecordsetClone
RS.MoveLast
' Exit if you cannot move to the last record (no records).
If Err <> 0 Then Exit Function
' Get the list of fields to autofill.
FillFields = ";" & F![AutoFillNewRecordFields] & ";"
' If there is no criteria field, then set flag indicating ALL
' fields should be autofilled.
FillAllFields = Err <> 0
F.Painting = False
' Visit each field on the form.
For Each C In F
' Fill the field if ALL fields are to be filled OR if the
' ...ControlSource field can be found in the FillFields list.
If FillALLFields Or _
InStr(FillFields, ";" & (C.Name) & ";") > 0 Then
C = RS(C.ControlSource)
End If
Next
F.Painting = True
End Function
注意:需要在窗体上先创建一个 文本框(Text box):
名称: AutoFillNewRecordFields
可见: No
默认值: Phone;Company Name;City;State;Zip (这里修改为你需要设置取上条记录的字段名) |
|