Copying last record--follow up ?

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
 
J

jp

Could you use the Escape key or Undo command to get out of the "New Record"
mode?

And here's another way to copy a record to the new record:
http://www.helenfeddema.com/access.htm (code #109)

jp



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
 
S

Steve Whitney

Using the Escape key once clears the default info, but a
second time does not take me back out of the new record.

However, after using the Escape key to clear the defaults,
I could navigate back out of the new record without it
being added. Good work-around if nothing else.

Any further thoughts?

Steve
-----Original Message-----
Could you use the Escape key or Undo command to get out of the "New Record"
mode?

And here's another way to copy a record to the new record:
http://www.helenfeddema.com/access.htm (code #109)

jp



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



--
Thanks!

jp lande
.
 
J

John Spencer (MVP)

You need to add a cancel button to the form.

UNTESTED AIRCODE for the button would be

Me.UNDO 'Clears the record of unsaved changes

'Now what do you want to do??
DoCmd.Close acForm, Me.Name 'close the open form

'Move back to the last record???????
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top