如何实现自动重复上一条记录的功能
编号:QA000484
建立日期: 1999年2月6日 最后修改日期:1999年2月6日
所属类别:
Chenjian:
Visual Foxpro中有一个功能:在数据窗录入记录时,当光标移向一个新的记录,会自动重复上一条记录的内容!在Access97和VB5中有办法实现吗?
回答:
VB和Access97都没有这样的功能。
在VB中,可以在执行AddNew之前先保存下当前记录,这可以利用Clone方法。如
Dim RS As Recordset
Set RS = YourRecordset.Clone
然后,在AddNew之后,利用RS的数据填充你的字段或控件。
在Access97中,可以先建立一个modAuto_Fill_New_Record模块,输入下面的代码:
Option Explicit
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 <&;gt; 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
然后在Form的OnCurrent事件中添加
=AutoFillNewRecord([Forms]![Customers])
这里Customers是你的Form的名字。
在窗体上建立一个TexBox,并设置如下属性:
Name: AutoFillNewRecordFields
Visible: No
DefaultValue: Phone;Company Name;City;State;Zip
Phone;Company Name;City;State;Zip表示你要重复上一条记录的字段。
此问题由李海回答。
| |
|
|
| |
|
|