Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 


March 2001

Taking Outlook to Task


RSS
Subscribe to Windows IT Pro | See More Visual Basic (VB) Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

Download the Code Here

The January 2001 and February 2001 installments of Outlook VBA on Demand highlighted problems you might encounter when you work with dates in Microsoft Outlook. In this installment, I continue that topic by showing you how to create Outlook task items for an all-too-common scenario—tasks that you must finish either this week or next week. The key to this programming job is a little function that returns the next available date that corresponds to a particular day of the week.

Meet GetNextDay()
The GetNextDay() function, which you see in Listing 1, contains two arguments: a date and an integer that represents the day of the week (starting with 1 for Sunday and ending with 7 for Saturday). Suppose today is Friday. If you use today's date and the integer 6 as your arguments, GetNextDay() returns the date for next Friday.

GetNextDay() uses two built-in Visual Basic (VB) functions that you'll probably find quite useful: Weekday() and DateAdd(). Weekday() takes any date and returns a number between 1 and 7 that represents the day of the week (with 1 representing Sunday).

DateAdd(), which lets you increase or decrease any date/time value by a specific number of units, uses the syntax

DateAdd(unit, number, date)

where unit is the interval you want to increase or decrease the date by. In Listing 1, the unit is "d" for days. You'll find the strings used for other intervals in the VBA Help file. (The procedures in Listing 4 use "ww" for weeks and "h" for hours.) The number argument is the number of intervals by which you want to increase or decrease the date. (You use a negative number to decrease.) Finally, date is the date you want to change.

Creating Tasks
The code you see in Listing 2 creates a new task for the current week, sets some basic properties, then displays the task so that the user can fill in additional information. The CreateThisWeekTask() procedure uses the GetNextDate() function to set the due date of the task to Friday of the current week:

.DueDate = _
  GetNextDay(Date(), 6)

Date() is an intrinsic VB function that returns the current day's date.

The CreateNextWeekTask() subroutine, which you see in Listing 3 has the same functionality as CreateThisWeekTask(). However, it uses GetNextDay() twice—first to set the task's start date to the following Monday, then to set the end date to the following Friday.

The solution in Listing 4 takes a different approach. The CreateTaskForXDay() subroutine prompts the user for the number of days necessary to complete the task. The subroutine depends on the GetNextWorkDay() function, which contains some useful user options: the number of days in the user's work week and whether the user wants the procedure to adjust the due date if it falls on a weekend. Notice that the subroutine also introduces a couple of operators—the \ division operator always rounds down to the nearest integer, and the Mod operator obtains the remainder from a division expression rather than the dividend.

Try It—You'll Like It
You probably find yourself creating many tasks that you must finish this week, next week, or in a specific number of days. If so, try out one (or more) of this column's subroutines. Just add the tool to your Outlook toolbar so that you can create a new task—with the dates already filled in—at the click of a button.

End of Article



Reader Comments
'Revision:
'Very usefull and helpfull Article, well done.
'But there is a little logical Mistake in the Function GetNextWorkDay().
'If it is a 5-days Week and the task comes out to be finished on Saturday,
'its O.K. to add 2 days. If the task comes out on Sunday, the Saturday is missing
'and this work day has to be added. Again 2 days have to be added.
'Different in a 6-days week. Saturdays I Add 0, as I Work on Saturday.
'Only Sundays in a 6-days week I add 1 as discribed in the code.

5-days Week: coming out on
'Saturday, O.K.
'Sunday, 1 day is missing
'Monday, if intExtraDays >2 -> 2 days are missing
'Tuesday, if intExtraDays >3 -> 2 days are missing

6-days Week: coming out on
'Saturday, 2 days too much -> 0
'Sunday, O.K.
'Monday, if intExtraDays >1 -> 1 day is missing
'Tuesday, if intExtraDays >2 -> 1 day is missing
'Wednesday, if intExtraDays >3 -> 1 day is missing

harald.bolender February 15, 2002


I liked your article, but what I am trying to find out is if there is any way to mine the data behind Outlook Tasks. One of our divisions uses a "divsional exchange mailbox acct" to assign and track tasks assigned to all the managers withing the division. The VP would then like a report that would show which tasks are past due, etc. I don't know if it is possible to get at the data fields that make up Outlook Tasks. Could you help me??

Thanks,



Lee Meaney March 16, 2004


This article helps me little. Which I need am, how I can recognize that the receiver of the task the date changed?
Thanks from germany

Reiner Kussmann May 06, 2004


Lee, when in doubt, check the object browser: Press ALt+F11 to open the VBA environment in Outlook, then press F2. Switch from <All Libraries> to Outlook to browse all Outlook objects and their properties, methods, and events.

Sue_Mosher August 19, 2004 (Article Rating: )


the article is really helpfull. I am using it to send mails using Outlook XP and 200. How cna I disable the security pop-up that comes in this case?

ketan daithankar October 02, 2004 (Article Rating: )


Please suggest a way to save data to user created/defined fields from vba/vb application.

thanks,
gagan, sachdeva_g@yahoo.com

Anonymous User December 02, 2004


You must be a registered user or online subscriber to comment on this article. Please log on before posting a comment. Are you a new visitor? Register now




Top Viewed ArticlesView all articles
Battery Life Issues Almost Certainly Not Windows 7's Fault

While Microsoft is still investigating a notebook battery life issue that was supposedly caused by Windows 7, some interesting trends have emerged. ...

Confirmed: Battery Life Issues Not Windows 7's Fault

Microsoft on Monday issued a lengthy statement about the recent Windows 7 battery controversy, echoing my assessment from earlier in the day, but backing it up with hard, cold evidence. Put simply, Windows 7 is not responsible for any battery life issues ...

Getting your iPhone to Sync with Exchange 2003

Follow these steps to use an iPhone with Exchange. ...


Exchange Server and Outlook Whitepapers Email Controls and Regulatory Compliance

Take Control of Your Email: Understand the Business Reasons for Email Storage Management

Related Events Top 5 Key Technologies Changing The Face of Exchange and Data Protection

Deep Dive into Windows Server 2008 R2 presented by John Savill

Bail Out Your Exchange Environment

Check out our list of Free Email Newsletters!

Exchange Server and Outlook eBooks Spam Fighting and Email Security for the 21st Century

Understanding and Leveraging Code Signing Technologies

The Expert's Guide for Exchange 2003: Preparing for, Moving to, and Supporting Exchange Server 2003

Related Exchange Server and Outlook Resources Introducing Left-Brain.com, the online IT bookstore
Looking for books, CDs, toolkits, eBooks? Prime your mind at Left-Brain.com

Discover Windows IT Pro eLearning Series!
Clear & detailed technical information and helpful how-to's, all in our trademark no-nonsense format

Exchange & Outlook UPDATE eNewsletter
News, strategies, products, and developments in Exchange Server and Outlook messaging.

Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro DevProConnections IT Job Hound
Left-Brain.com Technology Resource Directory asp.netPRO ITTV Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2010 Penton Media, Inc. Terms of Use | Privacy Statement