Results 1 to 4 of 4

Thread: Outlook Adding calendar evennt Bug

  1. #1

    Thread Starter
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539

    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:
    1. Private o1 As New Outlook.Application
    2.     Public Sub CreateAppointment() 'CreateAppointment(ByVal StartTime As Date, ByVal Endtime As Date, ByVal Subject As String, ByVal Location As String)
    3.         Try
    4.             'Create a reference to a Appointment item
    5.             Dim e1 As Outlook.AppointmentItem
    6.             'Create a new appointment item
    7.             e1 = o1.CreateItem(olAppointmentItem)
    8.             'Set a few of the many possible appointment parameters.
    9.  
    10.             e1.Start = CDate("23/01/2004 09:00:00")
    11.             e1.End = CDate("23/01/2004 10:00:00")
    12.             e1.Subject = "test"
    13.             e1.Location = "Bournemouth"
    14.             'If you want to set a list of recipients, do it like this
    15.             'e1.Recipients.Add Name
    16.             'Commit the appointment
    17.             e1.Send()
    18.             'Free up the space
    19.             e1 = Nothing
    20.         Catch er As Exception
    21.             MsgBox(er.ToString)
    22.         End Try
    23.     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

  2. #2
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    I have never tried this before, but this code appears to work. I would imagine you'd set more properties.

    VB Code:
    1. Dim oApp As Outlook.Application = New Outlook.Application
    2.         Dim item As Outlook.AppointmentItem = oApp.CreateItem(Outlook.OlItemType.olAppointmentItem)
    3.         item.Body = "From .NET"
    4.         item.Save()

  3. #3
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    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:
    1. Dim o1 As New Outlook.Application
    2.         'Create a reference to a Appointment item
    3.         Dim e1 As Outlook.AppointmentItem
    4.         'Create a new appointment item
    5.         'e1 = o1.CreateItem(olAppointmentItem) ==> olAppointmentItem is not declared
    6.         e1 = o1.CreateItem(Outlook.OlItemType.olAppointmentItem)
    7.         'Set a few of the many possible appointment parameters.
    8.  
    9.         'e1.Start = CDate("23/01/2004 09:00:00") ==> Invalid cast - maybe regional settings?
    10.         e1.Start = CDate("01/23/2004 09:00:00")
    11.         'e1.End = CDate("23/01/2004 10:00:00") ==> Invalid cast (again)
    12.         e1.End = CDate("01/23/2004 10:00:00")
    13.         e1.Subject = "test"
    14.         e1.Location = "Bournemouth"
    15.         'If you want to set a list of recipients, do it like this
    16.         'e1.Recipients.Add Name
    17.         'Commit the appointment
    18.         'e1.Send() ==> I changed from Send to Save, Send appears to send email
    19.         e1.Save()
    20.         'Free up the space
    21.         e1 = Nothing

  4. #4

    Thread Starter
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539
    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
  •  



Click Here to Expand Forum to Full Width