On Windows Prof XP and Outlook 2003 sp1 I get a Type Miss match er

H

Hotwheels

I get the type missmatch error when the code below trys to use
"For Each Appt In CalendarFolder.Items" .

The code works fine on 2000 and XP, one 2000 machine is using
Outlook 2003 sp1 fine with this code.

Is there a know problem with XP Prof and Outlook 2003 sp1?

Is there a work around I can use to go thru all the appointments
and find the one I want to alter.

Mike


Private mOut As Outlook.Application
Private Sub cmdMakeApp_Click()
Dim Prp As UserProperty
Dim i As Long
Dim bFound As Boolean
Dim MAPINameSpace As Outlook.NameSpace
Dim CalendarFolder As Outlook.MAPIFolder
Dim Appt As Outlook.AppointmentItem
On Error GoTo eh

bFound = False
If (mOut Is Nothing) Then Set mOut = CreateObject("Outlook.Application")
Set MAPINameSpace = mOut.GetNamespace("MAPI")
MAPINameSpace.Logon
Set CalendarFolder = MAPINameSpace.GetDefaultFolder(olFolderCalendar)
If (chkExsist.Value = 1) Then
For Each Appt In CalendarFolder.Items 'Problem place
If Not (Appt.UserProperties.Item("IDInteraction") Is Nothing) Then
If Appt.UserProperties.Item("IDInteraction").Value =
txtLabel.Text Then
bFound = True
Exit For
End If
End If
Next
End If
Set MAPINameSpace = Nothing
Set CalendarFolder = Nothing
If Not bFound Then Set Appt = mOut.CreateItem(olAppointmentItem)

Appt.Subject = "A Test"
Appt.Body = " A Test Appointment"
Appt.Location = "3rd Floor"


Appt.Start = "2/9/2005" + " " + "2:00 AM"
Appt.End = "2/9/2005" + " " + "3:00 AM"

If Not bFound Then Appt.UserProperties.Add "IDInteraction", olText

If (Not Appt Is Nothing) Then
If Not (bFound) Then
Appt.Save
If (mstrInteractionID = "") Then
Appt.UserProperties.Item("IDInteraction").Value =
txtLabel.Text
Else
oApp.UserProperties.Item("IDInteraction").Value =
txtLabel.Text
End If
Else
Appt.UserProperties.Item("IDInteraction").Value =
txtLabel.Text
End If
Appt.Save
End If
Set Appt = Nothing
Set mOut = Nothing
Unload Me
Exit Sub
eh:
Set mOut = Nothing
Err.Raise Err.Number, , Err.Description
Unload Me
End Sub
 
J

Jim Vierra

Not sure but it is possible to have non-calendar items in a calendar folder
in which case you should use an object to extract and then get it's type to
cast it.
 
H

Hotwheels

How do I How do I get it's type and cast it to use it as a
Outlook.AppointmentItem?
I tried the code on a different machine using the same OS and Same Outlook
and it worked fine so I think your guess of a problem in the calander folder
is right.

Mike
Dim CalendarFolder As Outlook.MAPIFolder
Dim Appt As Outlook.AppointmentItem
Dim oFolderItem as object


For Each oFolderItem In CalendarFolder.Items 'Problem place
How do I get it's type and cast it to use it as a
Outlook.AppointmentItem???
If Not (Appt.UserProperties.Item("IDInteraction") Is Nothing)
Then
If Appt.UserProperties.Item("IDInteraction").Value =
txtLabel.Text Then
bFound = True
Exit For
End If
End If
Next
 
J

Jim Vierra

I looked more closely at you code. Sorry I didn't see it before.

Look closely at the "oFolderItem In CalendarFolder.Items"
Don't you mean "oFolderItem In CalendarFolder.Folders"

Here's a less obtuse answer to the cast/test issue. I forget to change
languages at times.
dim oFolder as MAPIFolder
dim oAppt as AppointmentItem
dim oItem as object
....code...

For Each oItem In oFolder.Items
' all objects have a class property
if oItem.Class = Outlook.olAppointmentItem then ' or case it if you
test many.
set oAppt = oItem ' it's now an appointment item and exposes
the appointment items props and methods.
end if
Next

I have tried to test bad items with Outlook 2003 and find that it is now
very hard to create items of teh wrong type in a default folder. I used to
have problems with 97 when mailitems would get dropped accidentally into the
calendar folder and had to test each item before using it,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top