autofill new record

  • Thread starter Thread starter michaelNYC
  • Start date Start date
M

michaelNYC

I have a fuction that copies data from one record and
places it into a new record. I also want take the value
from one field in the old record and increment it by one
in the new record. Any suggestions.
 
I am no expert I just tweaked some code that can be found
in the MS Knowledge Base Article 210504, to make a new
record from the current record, not just the last record
as in the article. Here is the function. I've attached it
to a button on a form. It opens a new record and copies
the current information into it. If you place a text box
on the form with the defaut value equal to the control
field(s) you wish to autofill only those fields will be
carried to the new form otherwise all fields will be
copied.--

Option Compare Database
Option Explicit

Function AutoFillNewRecord(F As Form)

Dim RS As DAO.Recordset, C As Control
Dim FillFields As String, FillAllFields As Integer

Set RS = F.RecordsetClone



DoCmd.GoToRecord , , acNewRec





On Error Resume Next

' Exit if not on the new record.
If Not F.NewRecord 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
 
Back
Top