Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / January 2008

Tip: Looking for answers? Try searching our database.

Create a task from a userform

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Albert - 23 Jan 2008 02:04 GMT
Hi guys,

I am trying to create a task from a commandbutton in a userform.
This is what I got so far:
Sub CreateTask()

Dim oApp As Object
Set oApp = CreateObject("Outlook.Application")

Dim objTask As Object

Set objTask = oApp.CreateItem(olFolderTasks)
With objTask
   .Subject = "Test"
   .Body = "Test"
   .DueDate = DateValue("06/26/03")
   .Startdate = DateValue("06/26/03")
   .Send
   .Close olSave
End With
Set objTask = Nothing
End Sub

Obviously it is not working as I get a runtime error "Object does not
support the object or method" at the "duedate.

Can anyone help me with the correct code?

Thanks
Albert
JP - 23 Jan 2008 03:47 GMT
It should be "Set objTask = oApp.CreateItem(olTaskItem)"

"olFolderTasks" is the constant for the default Tasks folder.

HTH,
JP

> Hi guys,
>
[quoted text clipped - 26 lines]
> Thanks
> Albert
Albert - 23 Jan 2008 07:44 GMT
Hi JP,

Thanks for the response, but I still get the same error "Object does not
support the object or method" at the "duedate".

Albert

> It should be "Set objTask = oApp.CreateItem(olTaskItem)"
>
[quoted text clipped - 33 lines]
> > Thanks
> > Albert
JP - 23 Jan 2008 12:39 GMT
It worked on my machine, but I set a reference to the Outlook object
library. You should consider rewriting your code to take advantage of
this. For example:

Dim oApp As Outlook.Application ' not Object
Dim objTask As Outlook.TaskItem ' not Obect

Set oApp = New Outlook.Application ' early binding
Set objTask = oApp.CreateItem(olTaskItem)
With objTask
   .Subject = "Test"
   .Body = "Test"
   .DueDate = DateValue("06/26/03")
   .Startdate = DateValue("06/26/03")
   .Send
   .Close olSave  ' I believe this is moot as the item is already
closed/sent
End With

Set objTask = Nothing
Set oApp = Nothing
End Sub

You would need to set a reference to the Microsoft Outlook Object
Library by going to Tools>References in the VB Editor and locating the
appropriate OL. For example if you were using Office 2003, then it
would be "Microsoft Outlook 11.0 Object Library".

HTH,
JP

> Hi JP,
>
[quoted text clipped - 42 lines]
>
> - Show quoted text -
Albert - 23 Jan 2008 19:15 GMT
Hi JP,

I have changed the reference in VB tools and the code:
Sub CreateTask()
   Dim oApp As Outlook.Application ' not Object
   Dim objTask As Outlook.taskItem ' not Obect

   Set oApp = New Outlook.Application ' early binding
   Set objTask = oApp.CreateItem(olTaskItem)
   With objTask
       .Subject = "Test"
       .Body = "Test"
       .DueDate = DTPickerTaskduedate.Value 'DateValue("06/26/03")
       .Startdate = DTPicker1.Value         'DateValue("06/26/03")
       .Send

End With

Set objTask = Nothing
Set oApp = Nothing
End Sub

I am using office 12. I now get a error "you cannot send this task because
it is not in a valid state. Use the assign method first"

Any ideas?

Thanks
A

> It worked on my machine, but I set a reference to the Outlook object
> library. You should consider rewriting your code to take advantage of
[quoted text clipped - 73 lines]
> >
> > - Show quoted text -
JP - 23 Jan 2008 19:49 GMT
Is that Outlook 2007? I'm not familiar with that version. You might
want to repost your last message as a new topic, and be sure to
specify the version of Outlook.

Also you mentioned that you were running this from a command button on
a userform, if so shouldn't the Sub line be something like "Sub
CommandButton1_click()" ?

Sorry I couldn't be more help here.

--JP

> Hi JP,
>
[quoted text clipped - 105 lines]
>
> - Show quoted text -
 
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.