Finding Calendar items

A

Andy

Sorry to place this in 2 places on Access Groups but wasn't sure which SME
areas to place question.

I am trying to locate an item in Outlook Calendar folder using Access VBA.
I know the subject and the date of the appointment and that it is an All Day
Day Event. Can anyone help with the code ?

Something like :-

Dim olApp As Outlook.Application
Dim objCalendar As Object
Dim objAppointment As Object
Dim CalEntryID As Variant
Dim SQLcmd As String
Dim StaffID As Variant
Dim olNS As NameSpace
Dim olFolder As MAPIFolder
Dim olDataFolder As MAPIFolder
Dim olItem As AppointmentItem
Dim FDO as Variant

Set olApp = New Outlook.Application
Set olNS = olApp.GetNamespace("MAPI") ' open the MAPI Namespace

Set olFolder = olNS.GetDefaultFolder(olFolderCalendar)

FDO = Format(09/03/2006, "dd/mm/yyyy")

Set objAppointment = olFolder.Items.Find(Start = FDO AND Subject = "Long
Meeting" AND AllDayEvent = Yes)

or similar ????
 
S

Sue Mosher [MVP-Outlook]

You're close. You need quotes around your date string. See http://www.outlookcode.com/d/finddate.htm.

Also, the valid values for Boolean fields are True and False, not Yes and No.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
A

Andy

Thanks Sue - If my Search returns nothing in the line :-

Set objAppointment = olFolder.Items.Find(strFind) then I get the error :-

"object variable or with block variable not set" (I am calling from Access
97).

How do I deal with setting the objAppointment when the search returns no
items?

Thanks.
 
S

Sue Mosher [MVP-Outlook]

If the search returns no items, it means that either there are no items matching your conditions or the search query string doesn't accurately reflect the conditions you want to look for. When using Find, you always need to check whether you actually got an item:

On Error Resume Next
MsgBox strFind
Set objAppointment = olFolder.Items.Find(strFind)
If Not objAppointment Is Nothing Then
' it's safe to work with objAppointment, e.g.:
MsgBox objAppointment.Subject
End If

I strongly recommend using the first MsgBox statement above as you're developing the code. It's likely to show you any major problems with the search query rather fast.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
A

Andy

Great, all works now - Thanks.
----
Sue Mosher said:
If the search returns no items, it means that either there are no items matching your conditions or the search query string doesn't accurately reflect the conditions you want to look for. When using Find, you always need to check whether you actually got an item:

On Error Resume Next
MsgBox strFind
Set objAppointment = olFolder.Items.Find(strFind)
If Not objAppointment Is Nothing Then
' it's safe to work with objAppointment, e.g.:
MsgBox objAppointment.Subject
End If

I strongly recommend using the first MsgBox statement above as you're developing the code. It's likely to show you any major problems with the search query rather fast.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 

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