Setting a Default Value as the Value of another field

  • Thread starter Thread starter Kayleen H via AccessMonster.com
  • Start date Start date
K

Kayleen H via AccessMonster.com

How do I set a default value that displays the data in a previous field? For
example: In my form I have two dates - one date is Planned Start date, other
is Actual Start date. I would like the default value of the Actual Start date
to diplay the date in the Planned Start date field when the form is opened.
This date changes with the selection of the Actual Start date calendar
feature (that is already working well). Would also like the Actual Start
default value to be gray color, and when updated, black color. Anyone know
how to do that?
 
Can you not put something in the 'before update' event of the first text box.

Either straight in with:

txtActualStartDate.text=txtPlannedStartDate.text

or for greater control if you decide to change the dates in the furture:

If isnull(txtActualStartDate.text)=true then
txtActualStartDate.text=txtPlannedStartDate.text
End If
 
I tried that and it didn't work, but the field is a date field, not a text
field. Sorry, I'm an amateur at programming in Access, so my question is...
would the code below change if the field is text or date?
Can you not put something in the 'before update' event of the first text box.

Either straight in with:

txtActualStartDate.text=txtPlannedStartDate.text

or for greater control if you decide to change the dates in the furture:

If isnull(txtActualStartDate.text)=true then
txtActualStartDate.text=txtPlannedStartDate.text
End If
How do I set a default value that displays the data in a previous field? For
example: In my form I have two dates - one date is Planned Start date, other
[quoted text clipped - 4 lines]
default value to be gray color, and when updated, black color. Anyone know
how to do that?
 
You can use code in the after update event of one text box to set the value
of another text box:

If IsNull(Me.txtActualStartDate) Then
Me.txtActualStartDate = Me.txtPlannedStartDate
End If

I don't believe there is any method for setting (and maintaining) the format
properties of the Actual Start unless you have a value saved in the record
that stores whether or not the Actual Start value has been updated by the
user.

--
Duane Hookom
MS Access MVP
--

Kayleen H via AccessMonster.com said:
I tried that and it didn't work, but the field is a date field, not a text
field. Sorry, I'm an amateur at programming in Access, so my question
is...
would the code below change if the field is text or date?
Can you not put something in the 'before update' event of the first text
box.

Either straight in with:

txtActualStartDate.text=txtPlannedStartDate.text

or for greater control if you decide to change the dates in the furture:

If isnull(txtActualStartDate.text)=true then
txtActualStartDate.text=txtPlannedStartDate.text
End If
How do I set a default value that displays the data in a previous field?
For
example: In my form I have two dates - one date is Planned Start date,
other
[quoted text clipped - 4 lines]
default value to be gray color, and when updated, black color. Anyone
know
how to do that?
 
If you need something quick-and-dirty,

Add OnCurrent function (for the form) and OnAfterUpdate (for the control
with the PlannedDate). In those functions, check whether the Actual date is
null and, if so, set it to the value of the palnnedDate.

The problem with this method is that a user can "Undo" the setting of the
Planned Date but you'll be left with a value in the Actual Date. If it is ok
with you, great. If not, you have two options:

1) Just force a save of the record (commit of th transaction) in the
OnAfterUpdate routine (via DoCmd.Menu, for example)
2) Add OnUndo method to the Planned Date control and reset the value of
ActualDate .OldValue value.
 
Back
Top