Last record as imput for new record.

G

Goonynl

People,

I disabeled the option that when record is saved no changes can be made to
that record, because date, time and user is registrated with in the entry.

now i want to make it so that when a record is added the information of the
previous record is added as kind of default values in the new record.

how do i get this done
 
B

banem2

People,

I disabeled the option that when record is saved no changes can be made to
that record, because date, time and user is registrated with in the entry..

now i want to make it so that when a record is added the information of the
previous record is added as kind of default values in the new record.

how do i get this done

Hi,

There is a property DefaultValue of field which can be changed using
one line of code.

Use field event AfterUpdate and add (change FieldName to match field
name):

FieldName.DefaultValue = FieldName.Value

When you move to next record each field with above command will have
default value set as in previously updated record.

Regards,
Branislav Mihaljev
Microsoft Access MVP
 
G

Goonynl

Hi,

There is a property DefaultValue of field which can be changed using
one line of code.

Use field event AfterUpdate and add (change FieldName to match field
name):

FieldName.DefaultValue = FieldName.Value

When you move to next record each field with above command will have
default value set as in previously updated record.

Regards,
Branislav Mihaljev
Microsoft Access MVP

Thanks a lot, this indeed should do the trick, i'll be able to try this
later.
 
G

Goonynl

Hi,

There is a property DefaultValue of field which can be changed using
one line of code.

Use field event AfterUpdate and add (change FieldName to match field
name):

FieldName.DefaultValue = FieldName.Value

When you move to next record each field with above command will have
default value set as in previously updated record.

Regards,
Branislav Mihaljev
Microsoft Access MVP

indeed this works fine, but not completely what i was looking for.

the idea was that at the moment you select the new (still empty) record, it
fills up with some of the data in the record before (Query).

thanks in adv,
 
B

banem2

indeed this works fine, but not completely what i was looking for.

the idea was that at the moment you select the new (still empty) record, it
fills up with some of the data in the record before (Query).

thanks in adv,

Hi,

There are several ways to accomplish what you need:

- you can use query to filter last record and some code to set default
value
- you can use VBA to find last record and set default value
- simplest, but the slowest working solution is to use domain
aggregate functions
- probably you can force save on form close so it will "remember"
default values of fields

If you like any of the ideas and you cannot make it work, let me know.

Regards,
Branislav Mihaljev
Microsoft Access MVP
 
A

Arvin Meyer [MVP]

Goonynl said:
indeed this works fine, but not completely what i was looking for.

the idea was that at the moment you select the new (still empty) record,
it
fills up with some of the data in the record before (Query).

That will work after the first record is entered within the same session. It
will not work within a subsequent session. First you need to find the last
record entered. That may not be easy because your record source is a query
and the last record may not be within that data set.

Assuming that it is, you'll need to find the last record, which can only be
done if you use a sequential autonumber, or a timestamp. First find the last
record using a recordset the fill your values like (aircode):

Dim rst1 As DAO.Recordset
Dim rst2 As DAO.Recordset
Dim SQL As String
Dim db As DAO.Database

strSQL = "SELECT Max(ID) AS MaxID FROM MyTable;"

Set db = CurrentDb
Set rst1 = db.OpenRecordset (strSQL)

strSQL = "Select * From MyTable Where ID =" & rst1!MaxID

Set rst2 = db.OpenRecordset(strSQL)

' Now start setting your form's values
With rst2
Me.txtLastName = !LastName
Me.txtWhatever = !Whatever
' etc. to selective form controls
End With

I'd put this code in a command button. Add Error Handling and close your
objects, and you will get the last record to fill your form every time you
click the button.
 
D

David Portwood

Another possibility is to use a blank form not linked to the table. When the
form opens, open a recordset to find the last record in the table and
initialize the fields in the blank form accordingly. Include a "Save" button
on the form which inserts the data on the form as a new record in the table.
Entering a second record should be easy and fast, because the data from the
last record should still be there on the form and the recordset pointing to
the table won't be closed until the form closes.

On the negative side, if a data entry person is entering hundreds of
records, the necessity of clicking the "Save" button for each new record may
become irritating.
 

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