Inserting a date using code

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

Guest

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...
 
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
 
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
 
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
 
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
 
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top