Default values from previous records in datagrid subforms

B

Barry

Access 2003...
Creating a data entry form using a datagrid subform.

Data entry operators continually enter data for consecutive ranges and I
want to set default values to fields from the previous record. Every now and
again they will change the default values as well.

For example:
From To Value
0 1 X
1 2 Y
2 3 Z etc...

So, when creating the next record I want the default for 'From' to be the
previous value from the 'To' field.
If I can get that default set then I can also increment the 'To' value (e.g.
previous record + 1) so that the operator only needs to enter the 'Value'
field during data entry.

Every keystroke saved is a possible error avoided!

I've had a bit of a play around using the OnCurrent event and moving in the
recordset but it has not been robust enough for my liking.
 
A

Arvin Meyer [MVP]

In the AfterUpdate event of the control, use code similar to this:

Me.ControlName.DefaultValue = """" & Me.ControlName & """"

That's 4 double quotes on each side.
 
M

Marshall Barton

Barry said:
Access 2003...
Creating a data entry form using a datagrid subform.

Data entry operators continually enter data for consecutive ranges and I
want to set default values to fields from the previous record. Every now and
again they will change the default values as well.

For example:
From To Value
0 1 X
1 2 Y
2 3 Z etc...

So, when creating the next record I want the default for 'From' to be the
previous value from the 'To' field.
If I can get that default set then I can also increment the 'To' value (e.g.
previous record + 1) so that the operator only needs to enter the 'Value'
field during data entry.

Every keystroke saved is a possible error avoided!


This depends on how you define "previous". If it is the
record that appears above the new record, then "previous" is
totally dependent on how the loaded records are filtered and
sorted.

OTOH, if "previous" means the most recently created record,
then it depends on whether you are talking about the current
session or any session. If the latter, then you must have a
field in the table that can be used to identify the last
record to be created and use some code in the form's Load
event to lookup the value and set the DefaultValue
properties.

The current session case is the only one that is relatively
easy to deal with. Here, I think you can use the form's
AfterInsert event to set the DefaultValue property with code
like:
Me.txtFrom.DefaultValue = Me.txtTo
Me.txtTo.DefaultValue = Me.txtTo + 1
 
B

Barry

That worked a treat for regular records. Thanks.
You were all on the same line of thinking.

The datasheet was also requeried by a combo box on parent form so it only
showed one date of data entry.
So, select different date, do data entry for that date - usual thing.

I've also followed up with an event in the combo OnChange to also change the
defaults to the last record for that selected date of data so that the
previously entered values do not end up as defaults for the new record in a
different set of data. It makes complete sense if you see it in operation of
course... :)


Cheers

Lynton
 

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