A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Cannot Save Custom Form



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old January 18th 06, 09:10 AM posted to microsoft.public.outlook.program_vba
Dave Hogg
external usenet poster
 
Posts: 1
Default Cannot Save Custom Form

I am trying to create a task from a custom form. My code fails on the save
method, generating the following error message.

An unhandled exception of type 'System.Runtime.InteropServices.COMException'
occurred in microsoft.visualbasic.dll

Additional information: The operation failed.

My code is as follows.

datDueDate = Now
datDueDate = datDueDate.AddDays(7)

glbOutlookNewItem = glbOutlookDir.items.add("IPM.Task.CS Request")

glbOutlookNewItem.Subject = "Quote Acceptance Test"
glbOutlookNewItem.DueDate = datDueDate
glbOutlookUP = glbOutlookNewItem.UserProperties
glbOutlookUP("Start Date") = datDueDate
glbOutlookUP("Due Date") = datDueDate
glbOutlookNewItem.save()

I have tested that I can create and save a task in the folder manually.

Any suggestions would be great. Thanks
Ads
  #2  
Old January 19th 06, 05:00 PM posted to microsoft.public.outlook.program_vba
Dave Kane [MVP - Outlook]
external usenet poster
 
Posts: 33
Default Cannot Save Custom Form

glbOutlookUP("Start Date") is an object which your code is trying to set
equal to a Date. I can't tell how you've dimensioned your objects that
allowed you do that without getting a compiler error, but strong typing is
actually your friend. Make sure you have Option Strict and Option Explicit
turned on if you're working with COM Interop, to reduce your personal
hair-pulling quotient.

Try
glbOutlookUP("Start Date").Value = datDueDate
glbOutlookUP("Due Date").Value = datDueDate



"Dave Hogg" u17788@uwe wrote in message news:5a880cf39033b@uwe...
I am trying to create a task from a custom form. My code fails on the save
method, generating the following error message.

An unhandled exception of type
'System.Runtime.InteropServices.COMException'
occurred in microsoft.visualbasic.dll

Additional information: The operation failed.

My code is as follows.

datDueDate = Now
datDueDate = datDueDate.AddDays(7)

glbOutlookNewItem = glbOutlookDir.items.add("IPM.Task.CS
Request")

glbOutlookNewItem.Subject = "Quote Acceptance Test"
glbOutlookNewItem.DueDate = datDueDate
glbOutlookUP = glbOutlookNewItem.UserProperties
glbOutlookUP("Start Date") = datDueDate
glbOutlookUP("Due Date") = datDueDate
glbOutlookNewItem.save()

I have tested that I can create and save a task in the folder manually.

Any suggestions would be great. Thanks



  #3  
Old January 20th 06, 10:41 AM posted to microsoft.public.outlook.program_vba
Dave Hogg via OfficeKB.com
external usenet poster
 
Posts: 1
Default Cannot Save Custom Form

Dave,

Many thanks for the reply, and I do take your point about the hair pulling.
I have tried as you suggest, but it still fails. I have moved the 'Save' to
line 3 and it still fails.

There seem to be a lot of people who have posted a similar problem out there
on various forums. Could this be a .NET bug?

Dave Kane [MVP - Outlook] wrote:
glbOutlookUP("Start Date") is an object which your code is trying to set
equal to a Date. I can't tell how you've dimensioned your objects that
allowed you do that without getting a compiler error, but strong typing is
actually your friend. Make sure you have Option Strict and Option Explicit
turned on if you're working with COM Interop, to reduce your personal
hair-pulling quotient.

Try
glbOutlookUP("Start Date").Value = datDueDate
glbOutlookUP("Due Date").Value = datDueDate

I am trying to create a task from a custom form. My code fails on the save
method, generating the following error message.

[quoted text clipped - 23 lines]

Any suggestions would be great. Thanks


--
Message posted via http://www.officekb.com
  #4  
Old January 26th 06, 07:13 PM posted to microsoft.public.outlook.program_vba
Dave Kane [MVP - Outlook]
external usenet poster
 
Posts: 33
Default Cannot Save Custom Form

Actually, now that I look at your code more closely I think you've got an
earlier type conversion issue. I assume that glbOutlookDir is dimensioned as
a MAPIFolder object, and glbOutlookNewItem is presumably dimmed as a
TaskItem. The Outlook Items collection is not strongly typed - when you call
its Add method in VB.NET you get back an Object. You need to explicitly cast
that Object to make it a TaskItem or .NET will raise an exception.

If the Imports statement for your Outlook reference looks like this
Imports Outlook = Microsoft.Office.Interop.Outlook
the line where you instantiate your custom task item should be
glbOutlookNewItem = CType(glbOutlookDir.items.add("IPM.Task.CS
Request"),Outlook.TaskItem)

At that point you should verify the message class of your new item.

I hadn't noticed before that you were getting an "unhandled" exception - if
you wrap your code in try...catch blocks then you will be able to catch
exceptions so you can log the full exception details. That will help you to
determine where things start jumping the rails.

"Dave Hogg via OfficeKB.com" u17788@uwe wrote in message
news:5aa1fe15ccaaf@uwe...
Dave,

Many thanks for the reply, and I do take your point about the hair
pulling.
I have tried as you suggest, but it still fails. I have moved the 'Save'
to
line 3 and it still fails.

There seem to be a lot of people who have posted a similar problem out
there
on various forums. Could this be a .NET bug?

Dave Kane [MVP - Outlook] wrote:
glbOutlookUP("Start Date") is an object which your code is trying to set
equal to a Date. I can't tell how you've dimensioned your objects that
allowed you do that without getting a compiler error, but strong typing is
actually your friend. Make sure you have Option Strict and Option Explicit
turned on if you're working with COM Interop, to reduce your personal
hair-pulling quotient.

Try
glbOutlookUP("Start Date").Value = datDueDate
glbOutlookUP("Due Date").Value = datDueDate

I am trying to create a task from a custom form. My code fails on the
save
method, generating the following error message.

[quoted text clipped - 23 lines]

Any suggestions would be great. Thanks


--
Message posted via http://www.officekb.com



 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
custom form Charlie Outlook - Using Contacts 5 March 8th 06 05:24 PM
Custom Form Frustration Frustrated to the MAX! Outlook - Using Contacts 4 February 14th 06 07:35 PM
Custom form Melbin Outlook - Using Forms 1 January 24th 06 01:17 PM
I send an Outlook custom form, but a std. form displays? Sue Mosher [MVP-Outlook] Outlook - Using Forms 0 January 20th 06 08:41 PM
Cannot programmatically open custom message in custom form ms Outlook - Using Forms 1 January 20th 06 04:01 PM


All times are GMT +1. The time now is 08:37 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.