Wrox Programmer Forums
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 12th, 2003, 03:49 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 126
Thanks: 5
Thanked 0 Times in 0 Posts
Default Field Default

Good afternoon all,
I have a field (request date) in a table that is in a date/time format and defaulted as "now()". I have a second field (due date field) as date/time format and defaulted as "now() + 2" (To add two days). The only problem with this is that if this record is created on a Thursday or Friday it defaults to a Saturday or Sunday due date. How can I make this default and ignore the weekend?
Please help.

Regards,
Laura

The only thing standing between you and your goal is doubt. Quit doubting yourself and you'll be able to accomplish anything!
__________________
Regards,
Laura

The only thing standing between you and your goal is doubt. Quit doubting yourself and you'll be able to accomplish anything!
 
Old August 13th, 2003, 07:13 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Quote:
quote:Originally posted by lbreitenbach
How can I make this default and ignore the weekend?
Laura, on the form's On Open event, put this code:
Code:
Me.dtmDueDate.DefaultValue = DateAdd("d", 2, Me.dtmReqDate.DefaultValue)

Select Case Weekday(Me.dtmDueDate.DefaultValue)
   Case 7
      'Saturday; add two more days.
      Me.dtmDueDate.DefaultValue = DateAdd("d", 2, Me.dtmDueDate.DefaultValue)
   Case 1
      'Sunday; add one more day.
      Me.dtmDueDate.DefaultValue = DateAdd("d", 1, Me.dtmDueDate.DefaultValue)
   Case Else
      'Weekday; no action necessary.
End Select
Remember to change the names of the fields to match yours. Note: use DateAdd to add and subtract dates, don't just use + 2 or - 3, etc. You're adding a datatype byte to a datatype date. The results are not predictable.

Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division





Similar Threads
Thread Thread Starter Forum Replies Last Post
Default Field Values tachtenberg Reporting Services 1 February 19th, 2008 05:52 PM
Programmatically update field default value srcLakeJake Access VBA 6 October 26th, 2007 01:29 PM
Null inserted by form even when field has default Kia VB Databases Basics 1 July 24th, 2007 01:47 PM
Copy previous field record if next field is null ecampos Access VBA 6 June 23rd, 2006 12:55 PM
Update city field based on zip field nganb SQL Server ASP 0 April 22nd, 2004 10:30 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.