Microsoft Office Online
Sign in to My Office Online (What's this?) | Sign in

 
 
Microsoft Office Access
Search
Search
 
Check for updates: (c) Microsoft
Office downloads
 
 
 
Warning: You are viewing this page with an unsupported Web browser. This Web site works best with Microsoft Internet Explorer 6.0 or later, Firefox 1.5, or Netscape Navigator 8.0 or later. Learn more about supported browsers.

Email this linkEmail this link Printer-Friendly VersionPrinter-Friendly Version Bookmark and ShareShare
Calculating weekdays between two dates in Access
 

In Access, you can calculate the number of specific days of the week between two dates by using an expression. For example, you can enter a start date and an end date on a form and display the number of Wednesdays between the two dates. The following steps demonstrate this technique by creating a form, inserting text boxes and a combo box, and entering the expression.

  1. In the Database window, click Forms under Objects, and then click New.
  2. In the New Form dialog box, click Design View, and then click OK.
  3. Using the Text Box tool in the toolbox, add three unbound text boxes to your form.
  4. Set the Name property for the first text box to StartDate, the second to EndDate, and the third to NumOfDays.
  5. Set the Format property for the StartDate and EndDate text boxes to Short Date.
  6. Set the Control Source property for the NumOfDays text box to the following expression:
    =DateDiff("ww",[StartDate],[EndDate],[DayOfWeek])-Int([DayOfWeek]=Weekday([StartDate]))
  7. With the Control Wizards button in the toolbox pressed in, use the Combo Box tool to add a combo box to your form.
  8. On the first page of the Combo Box Wizard, click I will type in the values that I want.
  9. On the second page of the wizard, type 2 into the Number of columns text box.
  10. In the two columns, enter the following values:
    Col1 Col2
    Sunday 1
    Monday 2
    Tuesday 3
    Wednesday 4
    Thursday 5
    Friday 6
    Saturday 7
  11. On the third page of the wizard, click Col2 in the Available Fields box, and then click Finish.
  12. Set the Name property for the combo box to DayOfWeek.
  13. Switch to Form view.
  14. In the StartDate text box, type a start date (mm/dd/yy).
  15. In the EndDate text box, type an end date (mm/dd/yy).
  16. In the DayOfWeek combo box, click a day of the week in the drop-down list.

    The NumOfDays text box displays the number of occurrences of the weekday selected in the combo box.

Get Office 2007
Get Office 2007
advertisement