Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Trying to find an appointment in Outlook using both the subject and start time (using VBA)

627 views
Skip to first unread message

PW

unread,
Apr 5, 2013, 1:10:39 PM4/5/13
to
Hi,

I can find an appointment just using the subject field, but not
Outlook .subject And .start.

In debug, .start matches what I am searching for but the record is not
being found.

Dim olNS As Outlook.NameSpace
Dim olApptItem As Outlook.AppointmentItem
Dim olFolder As Outlook.MAPIFolder

Set olNS = olApp.GetNamespace("MAPI")
Set olFolder = olNS.GetDefaultFolder(olFolderCalendar)

Note: .Start is the field in Outlook that contains a date plus start
time ("3/25/2013 2:00:00 PM") .Subject = the subject field in Outlook
("Bass, Earnest T ETB13 Arraignment Date").

I set strStartDateTime = .Start (what I am going to write to Outlook:
.Start = Me.txtFollowUpDate + 1 + Me.txtStartTime)

Set olApptItem = olFolder.Items.Find("[subject] = '" & strSubject & "'
And [start] = '" & strStartDateTime & "'")

If Not TypeName(olApptItem) = "Nothing" Then 'Match found
blah, blah, blah
End If

An Outlook record with matching .Subject and .Start exists, so in the
line above olApptItem should not equal "Nothing" (but it does).

However:

Set olApptItem = olFolder.Items.Find("[subject] = '" & strSubject &
"'")

Does find the subject only and olApptItem = ("Bass, Earnest T ETB13
Arraignment Date")

I cannot just use the subject because there can be duplicates.

Any ideas how I can find an Outlook record using both the subject and
the start values?

-paulw

PW

unread,
Apr 5, 2013, 3:31:11 PM4/5/13
to
I got it. Thanks. Finally found a Google post that works
(http://social.msdn.microsoft.com/Forums/en-US/accessdev/thread/6007cd79-d17b-42d3-8c51-57c775bd3371/
Scroll to the last reply for the correct code).

I guess I also had to use .End (time) and format the date-times.

My version:

Dim olApp As Outlook.Application
Dim objCategory As Outlook.Category
Dim olNS As Outlook.NameSpace
Dim olApptItem As Outlook.AppointmentItem
Dim olCalFolder As Outlook.MAPIFolder

Dim strOLSubject As String
Dim strOLStartDateTime As String
Dim strOLEndDateTime As String
Dim strFind As String

.Start = Me.txtFollowUpDate + 1 + Me.txtStartTime
strOLStartDateTime = .Start

.End = Me.txtFollowUpDate + 1 + Me.txtEndTime

strOLEndDateTime = .End
strOLSubject = strOLSubject + " " + Trim(Me.txtCorrespondence_Type)

strFind = "[Start] = '" & Format(strOLStartDateTime, "ddddd h:nn
AMPM") & _
"' And [End] = '" & Format(strOLEndDateTime, "ddddd h:nn
AMPM") & "' " & _
" And [Subject] = '" & strOLSubject & "'"

Set olApptItem = olCalFolder.Items.Find(strFind)

If Not TypeName(olApptItem) = "Nothing" Then 'Match found
'messagebox to alert user that OL appt already exists.
End If

-paulw
0 new messages