📄 如何实现自动重复上一条记录的功能.txt
字号:
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表 示 你 要 重 复 上 一 条 记 录 的 字 段 。
<END>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -