vbscript - How to check if a calendar entry exists?

  • Thread starter Thread starter Long Nguyen
  • Start date Start date
L

Long Nguyen

Hi,

In my Outlook custom form I have this vbscript code that get an calendar
item:

Set olns = Item.Application.GetNameSpace("MAPI")
Set MyFolder1 = olns.Folders("Public Folders")
Set MyFolder2 = MyFolder1.Folders("All Public Folders")
Set MyFolder3 = MyFolder2.Folders("ITS")
Set MyFolder = MyFolder3.Folders("My Calendar")
Set olns = Nothing
Set strCalItem = MyFolder.Items("New request")


If the item "New Request" is not there Outlook would display the message
"Operation failed. An object could not be found."

I'd like to display a meaningful message to users. In vbscript how can I
check if the entry "New Requests" exists in the calendar (and if not display
the meaningful message).

Thanks
Long
 
If strCalItem Is Nothing Then
MsgBox "Operation failed. An object could not be found."
End If
 
Thanks Sue. But with the code

Set strCalItem = MyFolder.Items("New Request")
If strCalItem Is Nothing Then
MsgBox "Operation failed. An object could not be found."
End If

Outlook displayed the "Object could not be found" when it execute the Set
strCalItem statement, i.e. BEFORE the If check.

Regards
Long
 
Make sure you have an On Error Resume Next statement in the procedure's
declarations section.
 
Back
Top