What is the exact error? Are you sure the item in question is really an
appointment?
The fact that you Outlook says that it can no longer display the folder
contents is a very strong indication taht you are calling RDOSession.Logoff,
which you should never be doing if you are using a shared session.
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
Hmm, I don`t know. I didn´t compare times by the same code with
different methods. May be there is no significant difference.
Thanks for the hint to the Find/FindNext method. I use this method in
the creation/change code and the restrict method in a function which
is not very often used.
But here is the next problem:
Public Function FindAppointment(ByVal objCalendar As Object, ByVal
strEntryID As String) As Boolean
Const RES_AND As Long = 0
Const RES_NOT As Long = 2
Const RES_OR As Long = 1
Const RES_EXIST As Long = 8
Const RES_CONTENT As Long = 3
Const FL_SUBSTRING As Long = 1
Const FL_IGNORECASE As Long = &H10000
Const PR_SUBJECT As Long = &H37001E
Const PR_ENTRYID As Long = &HFFF0102
Dim CONTACT_ENTRY_ID As Long
Dim objRDOSession As Object
Dim objUtils As Object
Dim objRow
Dim objFilter
Dim objTable
Dim objAppointment As Outlook.AppointmentItem
Dim Columns(1)
Dim objRestrOR, objRestrAND1, objRestrAND2, objRestr1
Dim objRestr1a, objRestr1b, objRestr2, objRestr2a, objRestr2b
Dim strStoreID As String
CONTACT_ENTRY_ID = GetIdFromDaslProperty("ContactEntryID")
strStoreID = objCalendar.StoreID
Set objRDOSession = CreateObject("SafeOutlook.SecureRDOSession")
objRDOSession.Logon "", "", False, False, 0
Set objUtils = CreateObject("SafeOutlook.SecureMAPIUtils")
Set objTable = CreateObject("SafeOutlook.SecureMAPITable")
objTable.Item = objRDOSession.GetFolderFromID(objCalendar.EntryID,
objCalendar.StoreID).Items
Set objFilter = objTable.Filter
objFilter.Clear
Set objRestrOR = objFilter.SetKind(RES_OR)
Set objRestrAND1 = objRestrOR.Add(RES_AND)
Set objRestr1 = objRestrAND1.Add(RES_NOT)
Set objRestr1a = objRestr1.SetKind(RES_EXIST)
objRestr1a.ulPropTag = CONTACT_ENTRY_ID
Set objRestr1b = objRestrAND1.Add(RES_CONTENT)
objRestr1b.ulFuzzyLevel = FL_SUBSTRING Or FL_IGNORECASE
objRestr1b.ulPropTag = PR_SUBJECT
objRestr1b.lpProp = "Geburtstag von"
Set objRestrAND2 = objRestrOR.Add(RES_AND)
Set objRestr2a = objRestrAND2.Add(RES_EXIST)
objRestr2a.ulPropTag = CONTACT_ENTRY_ID
Set objRestr2b = objRestrAND2.Add(RES_CONTENT)
objRestr2b.ulFuzzyLevel = FL_SUBSTRING Or FL_IGNORECASE
objRestr2b.ulPropTag = CONTACT_ENTRY_ID
objRestr2b.lpProp = strEntryID
Columns(0) = PR_ENTRYID
Columns(1) = CONTACT_ENTRY_ID
objTable.Columns = Columns
If objFilter.FindFirst(True) Then
Do
objRow = objTable.GetRow
If Not IsEmpty(objRow) Then
Set objAppointment =
Outlook.Session.GetItemFromID(objUtils.HrArrayToString(objRow(0)),
strStoreID)
' Error: -2147221241 (80040107)
End If
Loop Until Not objFilter.FindNext(True)
End If
End Function
Interesting is the line "Set objAppointment = ...". Here araise an
error in 2007 if the folder (objCalendar) is a public folder. Same
item in the default calendar of the users mail box can be created with
out error. The item can also be created in a public folder with
2002/2003.
I´m not the Mapi-Expert and tell you only something what I have tried.
In 2002/2003 I use for RDOSessions the MAPIOBJECT method and for
2000/2007 I use the logon method. In 2000 there is no MAPIOBJECT so
there is no choose. If in 2007 I use the MAPIOBJECT some strange
things happens and will not work as expected. For example if a
RDOSession was started the user cannot longer access his folders and
have to restart Outlook. That`s the reasen to use the logon method.
Ok, but with this method the described error occurs.
Please help!
Peter
How much slower? Keep in mind that calling Restrict() will cause the
restriction to be persisted on the Exchange Server (if that is waht you
are
using) potentially causing a severe performance degradation. ExecSQL
collects rows one at a time avoiding IMAPITable::Restrict() MAPI call.
You can also always use RDOItems.Restrict - it takes a SQL expression and
returns a restricted collection.
If you know there will always be only or at most one item returned, use
RDOItems.Find, followed by (if you expect more items) FindNext.
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
"Peter Marchert" <
[email protected]> wrote in message
I use on some procedures the ExcecSQL method but it seems to be slower
than the restriction method? The code with the restriction is called
aproximately 100 times per second (or more). I create/change
appointments by looping through contact items. And on any item I have
to check if the appointment already exists.
Seems that one question is missing or I didn`t understand all answers:
Can I use the short entryid getting from an Exchange server to
reference a contact in a future Outlook session? Or is thi only the
case by using Mapi? Ken wrote in OOM I always get the long entryid but
I`m not sure if this is on Exchange so too.
Thanks Ken and Dmirty!
Peter
You might want to try the new (for version 4.4) MAPITable.ExecSQL
method -
you will be able to specify the conditions in the SQL format and specify
the
property names in the DASL (or OOM) format.
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
Yes, this was an own property created with a guid and I hard coded the
number tag by the hex value I spyed with Outlook Spy. This number tag
is different in pst and exchange. I tryed it with the GetIDsFromNames
and that works. This is my code to get the ID:
Private Function GetIdFromDaslProperty(ByVal strProperty As String) As
Long
Dim objItem As Object
Dim objSafeItem As Object
Dim PrProperty
On Error Resume Next
Set objSafeItem = CreateObject("Redemption.SafeMailItem")
Set objItem = g_objOutlook.CreateItem(olMailItem)
objSafeItem.Item = objItem
PrProperty = objSafeItem.GetIDsFromNames(DASLGUID, strProperty)
PrProperty = PrProperty + PT_STRING8
GetIdFromDaslProperty = PrProperty
Set objSafeItem.Item = Nothing
Set objSafeItem = Nothing
Set objItem = Nothing
End Function
Should this work reliably because I`m working with a unsaved mailitem?
In my test it works, but I´m not sure if it works on other machines/
configurations. Dmitry is working on the examples on his homepage with
the first item of a folder but may be the folder is empty.
Thanks for the code. PR_LONGTERM_ENTRYID_FROM_TABLE I cannot find in
Outlook Spy when opening a message on an exchange server. Where is
this property?
Last question: If a short entryid is only valid for the actual session
how can I store an id? Next time this Id may be different?
For example: Get the entryid of an contact and store it in an
appointmentitem. Outlook close and opens. Get this Id from the
appointmentitem and reference the contact. This should not work if I
understand this.
Thank you very much for your help!
Peter
On 4 Okt., 17:18, "Ken Slovak - [MVP - Outlook]" <
[email protected]>
wrote:
If this is a user property then short and long term id's don't apply.
Are you hard coding the property tag for that property or are you
using
a
call to a GetIdsFromNames method?
You should always use a call to a GetIdsFromNames method for anything
other
than a standard Outlook property, even properties added by Outlook
itself
such as ReminderSet. The numeric value of the property tag will differ
from
store to store, and store provider to store provider.
If you request an EntryID from a PST provider you will always get the
same
EntryID, that's a long-term id. If you request one from an Exchange
server
you might get a short-term id that's only valid for that Outlook
session.
In
MAPI tables you always ask for both types of id's and check to see
what
gets
returned. Here's the type of code I usually use for that (VB6, I can
show
C#
code if you want):
Public Const PR_ENTRYID = &HFFF0102
Public Const PR_LONGTERM_ENTRYID_FROM_TABLE = &H66700102
varColumns(0) = PR_ENTRYID
varColumns(1) = PR_LONGTERM_ENTRYID_FROM_TABLE
strEntryID = ""
If rdmFilter.FindFirst(True) Then
Row = .GetRow
If Not IsEmpty(Row) Then
strEntryID = rdmUtils.HrArrayToString(Row(1)) 'long term
If strEntryID = "" Then
strEntryID = rdmUtils.HrArrayToString(Row(0)) 'short term
End If
End If
--
...
Erfahren Sie mehr »- Zitierten Text ausblenden -
- Zitierten Text anzeigen -