Set Default Value of Date Field to that of Another Date Field

  • Thread starter Thread starter RH
  • Start date Start date
R

RH

I am working on a training database. I have a field "DateSerBeg" and a field
"DateSerEnd". I want the "DateSerEnd" to default to "DateSerBeg". Any
suggestions?
 
Use the "AfterUpdate" Event on the DateSerBeg field on your form to add this
code.
Me!DateSerEnd = Me!DateSerBeg
 
And, if you don't want the DateSerBeg value to overwrite a value that is
already in the DateSerEnd control, use this code:

If Len(Me!DateSerEnd & "") = 0 Then Me!DateSerEnd = Me!DateSerBeg
 
I am working on a training database. I have a field "DateSerBeg" and a field
"DateSerEnd". I want the "DateSerEnd" to default to "DateSerBeg". Any
suggestions?

The simplest way to do this is to use a Form to do all your data entry (this
is a good idea in any case; table datasheets aren't designed for the purpose).
Open the Form in design view, and find the "AfterUpdate" event on the Events
tab of the DateSerBeg control's properties. Click the ... icon by it, and
select Code Builder. Access will open a code-editing window with the Sub and
End Sub lines already filled in. Edit it to:

Private Sub DateSerBeg_AfterUpdate()
If IsNull(Me!DateSerEnd) Then
Me!DateSerEnd = Me!DateSerBeg
End If
End Sub

This code will check to see if there is anything already in DateSerEnd, and if
not, copy the DateSerBeg value into the control.
 
Back
Top