S
Steve Whitney
OK...I figured out how to implement Microsoft Knowledge
Base Article - 210236 on "How to Fill Record with Data
from Previous Record Automatically."
Now I've got a new problem:
The module automatically creates a new record when it
executes, so if I get into the "Add Record" mode by
mistake, I wind up with a new unwanted record that I
cannot delete from that screen.
The only way to delete the record seems to be to add yet
another record behind it, navigate to the unwanted record
and delete it then.
Is there a way to avoid having the new record added until
I am done entering the new data, so a user can "back out"
without entering an unwanted record?
Steve Whitney
(Below is the module and instructions from Article -
210236
To create and use the AutoFillNewRecord() function, follow
these steps:
Open the sample database Northwind.mdb.
Create a module and type the following line in the
Declarations section:Option Explicit
Type the following procedure:
Function AutoFillNewRecord(F As Form)
Dim RS As DAO.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
Save the module as modAuto_Fill_New_Record.
Open the Customers form in Design view. Change the
OnCurrent property of the form to read as
follows:=AutoFillNewRecord([Forms]![Customers])
Add a text box to the form, and set the following
properties: Text Box
Base Article - 210236 on "How to Fill Record with Data
from Previous Record Automatically."
Now I've got a new problem:
The module automatically creates a new record when it
executes, so if I get into the "Add Record" mode by
mistake, I wind up with a new unwanted record that I
cannot delete from that screen.
The only way to delete the record seems to be to add yet
another record behind it, navigate to the unwanted record
and delete it then.
Is there a way to avoid having the new record added until
I am done entering the new data, so a user can "back out"
without entering an unwanted record?
Steve Whitney
(Below is the module and instructions from Article -
210236
To create and use the AutoFillNewRecord() function, follow
these steps:
Open the sample database Northwind.mdb.
Create a module and type the following line in the
Declarations section:Option Explicit
Type the following procedure:
Function AutoFillNewRecord(F As Form)
Dim RS As DAO.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
Save the module as modAuto_Fill_New_Record.
Open the Customers form in Design view. Change the
OnCurrent property of the form to read as
follows:=AutoFillNewRecord([Forms]![Customers])
Add a text box to the form, and set the following
properties: Text Box