Repeat last Date Entry

  • Thread starter Thread starter Nylex
  • Start date Start date
N

Nylex

When entering records in thru a form I have a lot of same date entries
When entering the "Date" field i want it to be the same as the last record
Date but I dont want to be always pressing CTL' - there must be a simple way
of doing this

Tks
 
The easy way:

Set the default of the date field to the last value entered in that field?

Select the properties of the Control.

In the Default Value row of the "[TheDateControlName]" enter

=DLAST("[TheDateControlName]","[Thenameofthetable]")

Now, every time a new record is entered into, the default value of the date
field is set to the previous value. To add that date just press enter as it
gains focus.

Does thia answer your question??????

Regards
 
Steve:

A couple of points:

1. The property is the DefaultValue property, not the Default property,
which is something different.

2. The DefaultValue property is always a string expression regardless of
the data type so should be wrapped in quotes characters. This is especially
important with dates as otherwise the 'date' can be interpreted as an
arithmetical expression and give the wrong result.

So, putting both together gives:

Me!MyDate.DefaultValue = """" & Me!MyDate & """"

BTW don't be tempted to use the # date delimiter character in place of the
literal quotes. This is internationally unreliable as it requires the date
to be in US short date or an otherwise internationally unambiguous format.

You can handle this sort of thing generically by adding a function along
these lines to a standard module:

Public Function SetDefaultValue(ctrl As Control)

If Not IsNull(ctrl) Then
ctrl.DefaultValue = """" & ctrl & """"
End If

End Function

The function can then be called as the AfterUpdate event property of any
control which supports the Defaultvalue property like so:

=SetDefaultValue([Form].[ActiveControl])

Note the use of the Form property to reference the current form here. This
can be used in the properties sheet whereas Me can only be used in VBA.

Ken Sheridan
Stafford, England
 
Back
Top