Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / May 2007

Tip: Looking for answers? Try searching our database.

Inserting a date using code

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Don - 29 May 2007 19:43 GMT
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...
Signature

Don Rountree

Douglas J. Steele - 29 May 2007 20:21 GMT
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

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> 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...
Don - 29 May 2007 21:38 GMT
Thank you, this was helpfull.
Signature

Don Rountree

> Private Sub Form_Load()
>
[quoted text clipped - 14 lines]
> > 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...
Carl Rapson - 29 May 2007 20:34 GMT
> 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
Don - 29 May 2007 21:37 GMT
Thank you, this was helpful.
Signature

Don Rountree

> > I've got a form with a bound control - REP_DATE.  When the form opens, I
> > want
[quoted text clipped - 8 lines]
>
> Carl Rapson
Marshall Barton - 30 May 2007 01:28 GMT
>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.

Signature

Marsh
MVP [MS Access]

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.