OK, so the code that finally worked is below. Note change in line 10 . No
need to declare "olFolderTasks". Still have one more problem. I want to
attach an excel document to the task. Using .Attachments.Add = <filepath>
does not work. I get:
Argument not specified for parameter 'Source' of 'Public Overridable
Function Add(Source As Object, [Type As Object], [Position As Object],
[DisplayName As Object]) As Outlook.Attachment'.
NO idea what that means.
Any ideas?
****
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim olApp As Outlook.Application
Dim olNS As Outlook.NameSpace
Dim olFolder As Outlook.MAPIFolder
Dim olTaskItem As Outlook.TaskItem
Dim strbodyText As String
olApp = CreateObject("Outlook.Application")
olNS = olApp.GetNamespace("MAPI")
olFolder =
olNS.GetDefaultFolder(Outlook.OlDefaultFolders.olF olderTasks)
olTaskItem = olFolder.Items.Add("IPM.Task")
With olTaskItem
.Subject = "Rural Inspections "
.DueDate = Today
.ReminderTime = Now
.ReminderSet = True
.Categories = "Rural Projects"
.Save()
End With
olTaskItem = Nothing
olFolder = Nothing
olNS = Nothing
olApp = Nothing
Me.Close()
End Sub
End Class
****
"digger27" wrote:
Tosch,
Outlook.OlDefaultFolders.olFolderTasks show up as not being defined. If I
remove the .olFolderTasks and put quotes around the olFolderTasks to make the
line look like this:
olFolder = olNS.GetDefaultFolder("olFolderTasks")
I get the following error:
An unhandled exception of type 'System.InvalidCastException' occurred in
microsoft.visualbasic.dll
Additional information: Cast from string "olFolderTasks" to type 'Integer'
is not valid.
The line that is highlited is
olFolder = olNS.GetDefaultFolder("olFolderTasks")
Any ideas?
"Tosch" wrote:
try 'Outlook.OlDefaultFolders.olFolderTasks' and 'Today' for todays
date.
On Thu, 21 Apr 2005 06:28:01 -0700, "digger27"
<di******@discussions.microsoft.com> wrote:
I am trying to progamatically create tasks in Outlook using VB.Net. I am
using the following code:
****
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim olApp As Outlook.Application
Dim olNS As Outlook.NameSpace
Dim olFolder As Outlook.MAPIFolder
Dim olTaskItem As Outlook.TaskItem
Dim strbodyText As String
olApp = CreateObject("Outlook.Application")
olNS = olApp.GetNamespace("MAPI")
olFolder = olNS.GetDefaultFolder(olFolderTasks)
olTaskItem = olFolder.Items.Add("IPM.Task")
With olTaskItem
.Subject = "Rural Inspections "
.ReminderTime = "2:00:00 PM"
.ReminderSet = True
.Categories = "Rural Projects"
.Save()
End With
olTaskItem = Nothing
olFolder = Nothing
olNS = Nothing
olApp = Nothing
End Sub
****
VB tells me that "Name 'olFolderTasks' is not declared" Line 52.
I'm not sure what else to do to declare this variable. Should I delclare it
with "Dim" like the others above? If so suppose it would be something like:
Dim olFolderTasks As Outlook.??????
I'm pretty new to VB so sorry if this is a basic question.
Also, I would like to put the date on the subject line. In Excel I can use:
.Subject = "Rural Inspections " & Date$
but VB won't allow Date$, Date, or Date() here.
Thanks in advance.