vbscript - How to check if a calendar entry exists?

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
 
S

Sue Mosher [MVP]

If strCalItem Is Nothing Then
MsgBox "Operation failed. An object could not be found."
End If
 
L

Long Nguyen

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
 
S

Sue Mosher [MVP]

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

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