X
xyz
Hello,
I am writing a VB.Net application, wherein I am trying to get
appointments from outlook. The problem i am facing is that,sometimes i am
getting an error: "Cast not valid" for the line
myAppt = myAppts.GetFirst().
I have observed that i get this error mostly, when i already have the
outlook open.
Can anyone help me to overcome this problem?
Here is the piece of code:
Dim myolApp As New outlook.Application
Dim olNs As outlook.NameSpace
olNs = myolApp.GetNamespace("MAPI")
olNs.Logon(, , , False)
Dim myAppts As outlook.Items
Dim myAppt As outlook.AppointmentItem
myAppts =
olNs.GetDefaultFolder(outlook.OlDefaultFolders.olFolderCalendar).Items
'''''' Restricting the no. of appointments to get to a range of 20 days
around today''''
myAppt = myAppts.GetFirst()
Do While TypeName(myAppt) <> "Nothing"
''''Saving the appointments '''''''''
myAppt = myAppts.GetNext()
Loop
olNs = Nothing
System.Runtime.InteropServices.Marshal.ReleaseComObject(myolApp)
I am writing a VB.Net application, wherein I am trying to get
appointments from outlook. The problem i am facing is that,sometimes i am
getting an error: "Cast not valid" for the line
myAppt = myAppts.GetFirst().
I have observed that i get this error mostly, when i already have the
outlook open.
Can anyone help me to overcome this problem?
Here is the piece of code:
Dim myolApp As New outlook.Application
Dim olNs As outlook.NameSpace
olNs = myolApp.GetNamespace("MAPI")
olNs.Logon(, , , False)
Dim myAppts As outlook.Items
Dim myAppt As outlook.AppointmentItem
myAppts =
olNs.GetDefaultFolder(outlook.OlDefaultFolders.olFolderCalendar).Items
'''''' Restricting the no. of appointments to get to a range of 20 days
around today''''
myAppt = myAppts.GetFirst()
Do While TypeName(myAppt) <> "Nothing"
''''Saving the appointments '''''''''
myAppt = myAppts.GetNext()
Loop
olNs = Nothing
System.Runtime.InteropServices.Marshal.ReleaseComObject(myolApp)