PC Review


Reply
Thread Tools Rate Thread

Create a task from a userform

 
 
Albert
Guest
Posts: n/a
 
      23rd Jan 2008
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


 
Reply With Quote
 
 
 
 
JP
Guest
Posts: n/a
 
      23rd Jan 2008
It should be "Set objTask = oApp.CreateItem(olTaskItem)"

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


HTH,
JP

On Jan 22, 9:04*pm, Albert <Alb...@discussions.microsoft.com> wrote:
> 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


 
Reply With Quote
 
Albert
Guest
Posts: n/a
 
      23rd Jan 2008
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

"JP" wrote:

> It should be "Set objTask = oApp.CreateItem(olTaskItem)"
>
> "olFolderTasks" is the constant for the default Tasks folder.
>
>
> HTH,
> JP
>
> On Jan 22, 9:04 pm, Albert <Alb...@discussions.microsoft.com> wrote:
> > 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

>
>

 
Reply With Quote
 
JP
Guest
Posts: n/a
 
      23rd Jan 2008
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

On Jan 23, 2:44*am, Albert <Alb...@discussions.microsoft.com> wrote:
> 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
>
>
>
> "JP" wrote:
> > It should be "Set objTask = oApp.CreateItem(olTaskItem)"

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

>
> > HTH,
> > JP

>
> > On Jan 22, 9:04 pm, Albert <Alb...@discussions.microsoft.com> wrote:
> > > 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- Hide quoted text -

>
> - Show quoted text -


 
Reply With Quote
 
Albert
Guest
Posts: n/a
 
      23rd Jan 2008
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

"JP" wrote:

> 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
>
> On Jan 23, 2:44 am, Albert <Alb...@discussions.microsoft.com> wrote:
> > 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
> >
> >
> >
> > "JP" wrote:
> > > It should be "Set objTask = oApp.CreateItem(olTaskItem)"

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

> >
> > > HTH,
> > > JP

> >
> > > On Jan 22, 9:04 pm, Albert <Alb...@discussions.microsoft.com> wrote:
> > > > 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- Hide quoted text -

> >
> > - Show quoted text -

>
>

 
Reply With Quote
 
JP
Guest
Posts: n/a
 
      23rd Jan 2008
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

On Jan 23, 2:15*pm, Albert <Alb...@discussions.microsoft.com> wrote:
> 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
>
>
>
> "JP" wrote:
> > 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

>
> > On Jan 23, 2:44 am, Albert <Alb...@discussions.microsoft.com> wrote:
> > > 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

>
> > > "JP" wrote:
> > > > It should be "Set objTask = oApp.CreateItem(olTaskItem)"

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

>
> > > > HTH,
> > > > JP

>
> > > > On Jan 22, 9:04 pm, Albert <Alb...@discussions.microsoft.com> wrote:
> > > > > 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- Hide quoted text -

>
> > > - Show quoted text -- Hide quoted text -

>
> - Show quoted text -


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Floating userform appears on task bar??? Robert Crandal Microsoft Excel Programming 4 7th Dec 2009 09:33 AM
Why does typing a new task create duplicate entries in the task li Northesk34 Microsoft Outlook Discussion 1 21st May 2009 11:28 PM
Task Scheduler: Create task to open webpage? Ken Isaacson Windows Vista General Discussion 0 13th May 2009 02:41 PM
Can I create a userform in Excel to create an appointment in Outlo =?Utf-8?B?U3Bpa2U0?= Microsoft Excel Programming 1 18th Dec 2006 09:44 AM
Create Assigned Task Without 'Send me a status report when this task is complete' enabled bassman5 Microsoft Outlook Interoperability 0 23rd Sep 2005 12:07 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:31 PM.