Inserting a date using code

D

Don

I've got a form with a bound control - REP_DATE. When the form opens, I want
this control populated with the next day's date, unless the next day is
Saturday. In that case, I want the next Monday's date entered into the
control. Can somebody show me the syntax of how that happens? Thanks...
 
D

Douglas J. Steele

Private Sub Form_Load()

Select Case Weekday(Date())
Case vbFriday
Me!REP_DATE = DateAdd("d", 3, Date())
Case vbSaturday
Me!REP_DATE = DateAdd("d", 2, Date())
Case Else
Me!REP_DATE = DateAdd("d", 1, Date())
End Select

End Sub
 
C

Carl Rapson

Don said:
I've got a form with a bound control - REP_DATE. When the form opens, I
want
this control populated with the next day's date, unless the next day is
Saturday. In that case, I want the next Monday's date entered into the
control. Can somebody show me the syntax of how that happens? Thanks...

In Form_Current:

Me.REP_DATE = IIf(Weekday(DateAdd("d", 1, Date)) = 7, DateAdd("d", 3,
Date), DateAdd("d", 1, Date))

Carl Rapson
 
D

Don

Thank you, this was helpful.
--
Don Rountree


Carl Rapson said:
In Form_Current:

Me.REP_DATE = IIf(Weekday(DateAdd("d", 1, Date)) = 7, DateAdd("d", 3,
Date), DateAdd("d", 1, Date))

Carl Rapson
 
D

Don

Thank you, this was helpfull.
--
Don Rountree


Douglas J. Steele said:
Private Sub Form_Load()

Select Case Weekday(Date())
Case vbFriday
Me!REP_DATE = DateAdd("d", 3, Date())
Case vbSaturday
Me!REP_DATE = DateAdd("d", 2, Date())
Case Else
Me!REP_DATE = DateAdd("d", 1, Date())
End Select

End Sub
 
M

Marshall Barton

Carl said:
In Form_Current:

Me.REP_DATE = IIf(Weekday(DateAdd("d", 1, Date)) = 7, DateAdd("d", 3,
Date), DateAdd("d", 1, Date))


no, No, NO!
You should ***NEVER*** set a bound control or field's value
in the Current event.

If you do, simply navigating through the records in the form
will dirty and save every record that you look at,
eventually leading to all kinds of catestrophic failures.
 
Top