Using After Update to set Default Value

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Good Morning,
I want to use the currently entered value to prefill the next new record.
On the afterupdate event of the Text box formatted as ShortDate I have the
following code:
If (Not IsNull(Me.EventDate)) Then
Me.EventDate.DefaultValue = Me.EventDate
End If
I have also tried:
If (Not IsNull(Me.EventDate)) Then
Me.EventDate.DefaultValue = """" & Me.EventCallDate & """"
End If
Either way, I get the following result:
Enter 2/1/2005, go to a new record, and the value shows as 12/30/1899

On a combo box, I was unsuccessfully trying to do the same thing with the
employee ID:
If (Not IsNull(Me.ID)) Then
Me.ID.DefaultValue = Me.ID
End If
I have also tried this version with the quotes and ampersands. Both result
in a blank value when I go to a new record.
I would appreciate any support :)

Thanks in advance
 
On the date field problem, is the control source for the EventDate field
defined as a date type in the underlying table?

If so, then you have to put the # sign date delimiter around the value that
you're sticking into the default value. That way, the underlying table
field sees a date and is happy. Otherwise, it just sees a string that is
cannot interpret as a date, and gives you the 12/30/1899 value.

To do this, you code should read:

Me.EventDate.DefaultValue = "#" & Me.EventDate & "#"

This is the way to specify a date in a string


What type of table field is the control source for your ID field in the
second question? Also, what is the list source for your combo box and do
you have Limit To List = yes?
 
The table and form are date data types, changing the """" to "#" worked
wonderfully except for one issue. Both the table and the form do not have a
default value for this date field. The default value is only added on the
after update event. The form is set to data entry true. When I open the form,
it now defaults to 12/30/1899. After I add a new record, the entered date
will prefill the next new record perfectly. How to a fix the opening value?

The datatype of the source table for the ID is text, and the combo box is
set to limit to the list.

Thank you again for your Support JP :)

Renee
 
Renee,

Check and make sure that there is no default value in the default value
property field of the form -- it may have picked up a permanent default
value along the way.

Also, you could just assign a default value in the form open event. For
example, you could put in a line that says

Me.EventDate.DefaultValue = now()

The Now function returns the current date. I'm not sure if you would have
to put the # around it, so try it both ways.
 
I added a default value as today's date, and on the form close event reset
the any default values that changed during form use.
Thank you for your help JP!
 
Back
Top