|
-
Jan 23rd, 2004, 06:09 AM
#1
Thread Starter
Fanatic Member
Outlook Adding calendar evennt Bug
Can anyone please help on this
Ive found some code to insert a calendar event into outlook, ive seen loads and loads of posts with this same code but none of them work
heres the code
VB Code:
Private o1 As New Outlook.Application
Public Sub CreateAppointment() 'CreateAppointment(ByVal StartTime As Date, ByVal Endtime As Date, ByVal Subject As String, ByVal Location As String)
Try
'Create a reference to a Appointment item
Dim e1 As Outlook.AppointmentItem
'Create a new appointment item
e1 = o1.CreateItem(olAppointmentItem)
'Set a few of the many possible appointment parameters.
e1.Start = CDate("23/01/2004 09:00:00")
e1.End = CDate("23/01/2004 10:00:00")
e1.Subject = "test"
e1.Location = "Bournemouth"
'If you want to set a list of recipients, do it like this
'e1.Recipients.Add Name
'Commit the appointment
e1.Send()
'Free up the space
e1 = Nothing
Catch er As Exception
MsgBox(er.ToString)
End Try
End Sub
i keep getting an error of
"System.InvalidCastExeception: Specified cast is not valid"
ive also found this but havnt tried it as of yet
http://support.microsoft.com/default...;en-us;Q309336
Is this article releated to my problem
I am curretly building a defect management system for software and web developers,
If you wana try it out (beta test) and keep it for free just send me a message
-
Jan 23rd, 2004, 05:55 PM
#2
Frenzied Member
I have never tried this before, but this code appears to work. I would imagine you'd set more properties.
VB Code:
Dim oApp As Outlook.Application = New Outlook.Application
Dim item As Outlook.AppointmentItem = oApp.CreateItem(Outlook.OlItemType.olAppointmentItem)
item.Body = "From .NET"
item.Save()
-
Jan 23rd, 2004, 06:10 PM
#3
Frenzied Member
I really should be working. Anyway, since I've been wanting to do this (although on a PDA) I copied your code into VS and tweaked it until it worked.
I too, was getting invalid cast, it did not like the date string 23/01/2004 - but I'm in the US, so I guess that makes sense.
Anyway, here's your adulterated code:
VB Code:
Dim o1 As New Outlook.Application
'Create a reference to a Appointment item
Dim e1 As Outlook.AppointmentItem
'Create a new appointment item
'e1 = o1.CreateItem(olAppointmentItem) ==> olAppointmentItem is not declared
e1 = o1.CreateItem(Outlook.OlItemType.olAppointmentItem)
'Set a few of the many possible appointment parameters.
'e1.Start = CDate("23/01/2004 09:00:00") ==> Invalid cast - maybe regional settings?
e1.Start = CDate("01/23/2004 09:00:00")
'e1.End = CDate("23/01/2004 10:00:00") ==> Invalid cast (again)
e1.End = CDate("01/23/2004 10:00:00")
e1.Subject = "test"
e1.Location = "Bournemouth"
'If you want to set a list of recipients, do it like this
'e1.Recipients.Add Name
'Commit the appointment
'e1.Send() ==> I changed from Send to Save, Send appears to send email
e1.Save()
'Free up the space
e1 = Nothing
-
Jan 26th, 2004, 10:32 AM
#4
Thread Starter
Fanatic Member
Hey Thanks Mike Hildner
Your code is a dream the cast from string was caused because the way the outlook stuff was called however i kept getting an msg from outlook asking if i wana allow another program to use outlook which was kinda annoying because it was then dependant on the user clicking yes
So thanks loads man
I am curretly building a defect management system for software and web developers,
If you wana try it out (beta test) and keep it for free just send me a message
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|