VB icon

Add Outlook Tasks

Email
Submitted on: 1/11/2015 8:01:00 AM
By: Troy Blake (from psc cd)  
Level: Beginner
User Rating: By 7 Users
Compatibility: VB 5.0, VB 6.0
Views: 1987
 
     Used to show and add new tasks to Outlook. Simple code to demo getting task list and also adding a new task in Outlook. Please vote.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: Add Outlook Tasks
' Description:Used to show and add new tasks to Outlook. Simple code to demo getting task list and also adding a new task in Outlook. Please vote.
' By: Troy Blake (from psc cd)
'
' Assumes:Create Reference to Outlook. Create a form, insert code. Also put a combobox on the form and name it cboTasklist. Load form at runtime to view current task list. Simple code to demo getting task list and also adding a new task. Not very useful as it is listed here, but you can see how you could change it to be a useful function. Please vote.
'**************************************

'Simple Outlook Task View/Add Code
'Troy Blake - Logan's Roadhouse, Inc.
Private Sub InitForm()
 'Loads current task to dropdown, then adds
 'a task for John Smith. John gets the task
 'sent to him via Outlook.
 Dim oApp as Outlook.Application
 Dim oNspc as NameSpace
 Dim oItm as TaskItem
 Dim myItem as TaskItem
 Set oApp = CreateObject("Outlook.Application")
 Set oNspc = oApp.GetNamespace("MAPI")
 For Each oItm in oNspc.GetDefaultFolder(olFolderTasks).Items
'Loop through all tasks and show subject 
'in dropdown.
With Me.cboTasklist
 .AddItem (oItm.Subject)
End With
 Next oItm
 oNspc.GetDefaultFolder(olFolderTasks).Items.Add
 Set myItem = oApp.CreateItem(olTaskItem)
 'Create a new task
 With myItem
.Subject = "Subject"
.Assign = "Assign"
.Body = "Task Body"
.PercentComplete = 10
'Set due date for tomorrow
.DueDate = DateAdd("d",1,Date)
.ReminderSet = True
.ReminderTime = "9:00 AM"
'Outlook name of person to get task
.Recipients.Add "John Smith"
.Close (olSave)
 End With
 'Send the task (like email)
 myItem.Send
 Set myItem = Nothing
 Set oItm = Nothing
 Set oNspc = Nothing
 Set oApp = Nothing
End Sub
Private Sub Form_Load()
 'Call out sample sub at form load
 InitForm
End Sub


Other 2 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.