Calendar Search

Status
Not open for further replies.

LMS

Senior Member
Outlook version
Email Account
Exchange Server
I created thru you the macro that when I open up a contact and run the macro, it searches the calendar for the last name of the contact throughout the calendar.

But when I open the contact thru the shortcut (which we fixed just recently for the combobox macro), the macro for the calendar search does not run.

The macro you gave me was the folowing and the line : Set oContact = ActiveExplorer.Selection.Item(1): shows up yellow from the debug etc.

Any way to fix this one as well??

Thanks so much!!

Sub Search_Calender()

Dim myOlApp As New Outlook.Application

Dim ns As Outlook.NameSpace

Dim strFilter As String

Dim oContact As Outlook.ContactItem


Set ns = myOlApp.GetNamespace("MAPI")


Set oContact = ActiveExplorer.Selection.Item(1)


' use oContact.FullName to search on the name

strFilter = oContact.LastName


Set myOlApp.ActiveExplorer.CurrentFolder = ns.GetDefaultFolder(olFolderCalendar)


txtSearch = strFilter

myOlApp.ActiveExplorer.Search txtSearch, olSearchScopeAllFolders

Set myOlApp = Nothing

End Sub
 
thanks....but that did not solve it...and here is the line that goes yellow from the debug

strFilter = oContact.Email1Address
 
It looks like its not detecting the contact and getting the email address from it.
 
So why does the calendar search of the last name need to identify the email?

What to fix please?
 
i was basing that comment on your line in the post before it:

strFilter = oContact.Email1Address
 
you need a strfilter = line in it - so if you have two, then delete it, otherwise change it to the field you want to use.
 
thank you...so this is the line and what words do I replace and what are the words to the calendar field please?

strFilter = oContact.Email1Address
 
and just to be clear, this macro works when I open up a contact from the folder, but doesn't work when I open up the contact from the shortcut in the calendar
 
strFilter = oContact.Lastname

This is what you'd use for the last name field. If it doesn't work, I don't know what is wrong. When you open the contact from a shortcut, It's not seen as the current item, which I causes problems with the macro.
 
This is the macro you gave me that works from opening up the contact from the folder and not when I open up the contact from the shortcut to the contact.

So want to make this clear and see if there is anything you suggest that fixes it for running after I open up the contact from the shortcut to the contact.

And as a reminder, we fixed the similar problem with the other macros and you had me delete certain lines.

So, any new thoughts in details please?

Sub Search_Calender()

Dim myOlApp As New Outlook.Application

Dim ns As Outlook.NameSpace

Dim strFilter As String

Dim oContact As Outlook.ContactItem


Set ns = myOlApp.GetNamespace("MAPI")


Set oContact = ActiveExplorer.Selection.Item(1)


' use oContact.FullName to search on the name

strFilter = oContact.LastName


Set myOlApp.ActiveExplorer.CurrentFolder = ns.GetDefaultFolder(olFolderCalendar)


txtSearch = strFilter

myOlApp.ActiveExplorer.Search txtSearch, olSearchScopeAllFolders

Set myOlApp = Nothing

End Sub
 
And in another forum someone said the following, but it's not anything I understand.....so do you have a thought for fixing this code?

"a) You cannot set a variable that's declared as ContactItem to an object that is not a ContactItem.

b) ActiveExplorer.Selection(1) gives you a reference on the first selected item in a folder whereas ActiveInspector.CurrentItem gives you the ref on the open item.

That is if you want to access an open item, then don't use ActiveExplorer.Selection. You made the same error with your first code."
 
I replaced ActiveExplorer.Selection(1) with ActiveInspector.CurrentItem and it is now fixed!!

Thanks for your time as usual!!!
 
Glad you figured it out - I was visiting family over the weekend.
 
As I have said in the past, this is not my area of expertise, and I truly appreciate your great support online!
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
S outlook 2007 calendar search Using Outlook 6
S Outlook 2007 Calendar instant search problem. Windows 7 Using Outlook 4
S Outlook 2007 Calendar instant search problem. Windows 7 Using Outlook 0
P Outlook search is not working at all for Calendar & Tasks Using Outlook 7
D Exchange to iOS Calendar Search Exchange Server Administration 5
J Calendar search failing & wrong indexlocation showing..OL2010 Using Outlook 3
A OL13 Calendar Search not finding most items Using Outlook 15
G Outlook 2013 - Search Returning All Calendar Entries Using Outlook 1
J Calendar Search by Category not showing expected results Using Outlook 7
B How can I narrow the search in my Outlook calendar? Using Outlook 0
C Outlook 2010 search for question mark in calendar Using Outlook 7
J Cannot search items within shared calendar Using Outlook 0
Fozzie Bear Calendar Events created on iPhone have suddenly start sending invitations to attendees Using Outlook 2
J Set calendar default to 'none' (policy) Exchange Server Administration 3
J Calendar events created on iPhone automatically changing default alert from 'None' to 'Time of Event' Using Outlook.com accounts in Outlook 0
G Outlook 365 My iCloud Outlook doesn’t work after reinstalling Microsoft365 on Windows 10 PC – now I get error message on contacts and calendar Using Outlook 1
G Creating Macro to scrape emails from calendar invite body Outlook VBA and Custom Forms 6
U When opening shared Calendar "The set of folders cannot be opened" Using Outlook 0
P Can no longer sync Outlook with iPhone calendar after iPhone update to 17.1.1 Using Outlook 7
P turn off the default "all day" check box in new calendar items. How? Using Outlook 1
A Outlook 365 New Appointments All saved to a 365 default calendar on Mac Using Outlook 0
V Unchecking my calendar and leaving shared one visible Outlook VBA and Custom Forms 1
V VBA Categories unrelated to visible calendar and Visual appointment Categories Outlook VBA and Custom Forms 2
M New Calendar Appointments: Conditionally turn off reminder and show time as free Using Outlook 5
J Cannot edit a calendar event received as an invitation Using Outlook 2
H Outlook 365 O365 outlook calendar item editing Using Outlook 1
Kika Melo Outlook Calendar deleted appointments not in Deleted Items folder Using Outlook 3
P Copying ALL calendar entries from Calender in PST file to IMAP OST file? Using Outlook 1
e_a_g_l_e_p_i Question about calendar Using Outlook 5
icacream Outlook 2021 - Google calendar in the peek Using Outlook 0
e_a_g_l_e_p_i MY Outlook 2021 changed the format of the shortcuts for mail, calendar etc. Using Outlook 10
Fozzie Bear Shared Calendar For Scheduled Tasks Using Outlook.com accounts in Outlook 3
K Add an entry to a specific calendar Using Outlook 1
F Add a category before "Send an Email When You Add an Appointment to Your Calendar" Outlook VBA and Custom Forms 0
L Synch Outlook 365 calendar with iPhone Using Outlook 0
C Recover calendar Using Outlook 0
R How to prevent corrupted Notes format in Calendar and Contacts Using Outlook 0
L Duplicate calendar entries in Outlook 365 Using Outlook 3
G Stop Outlook 365 adding meetings to calendar Using Outlook 1
CWM550 Outlook 365 HELP! Calendar Craziness! Using Outlook 5
J Event/Meeting in Outlook Does Not Align with SharePoint Calendar Using Outlook 5
Commodore Slow calendar Using Outlook 0
C How to import Outlook calendar? Using Outlook 1
G Add contacts birthday to calendar Using Outlook 4
e_a_g_l_e_p_i Outlook 2021 all appointments not showing in calendar Using Outlook 2
V iCloud calendar problems, Outlook shuts down immediately Using Outlook 2
KeithJB iCloud calendar sync only works one way! Using Outlook 3
V Backup Calendar, Contacts, Tasks in an POP3 data file Using Outlook 3
O Unable to make changes to an existing Calendar entry Using Outlook 11
J VBA for outlook to compare and sync between calendar Outlook VBA and Custom Forms 1

Similar threads

Back
Top