UserForm Code For Contact Links

Status
Not open for further replies.

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
To the SMART WOMAN!!!!;););)I have the following code in a UserForm which has two comboxes, and the first comboxbox is my list of categories...and the second combobox shows the contact names of the contacts that are a part of the category I click on in the first combobox....but the name of the contact is not a link to the contact....so is there a quick fix to this so that the line which is:
Me.ddlContacts.addItem ctc.FullName is changed so it is not just the FullName of the contact, but the link to the contact....

so here is the code and I appreciate a quick response and it solves everything for me.....thanks much:

Private Sub ddlCategories_Change()
Dim objOutlook As outlook.Application
Dim objNS As outlook.NameSpace
Dim objFolder As outlook.MAPIFolder
Dim objFolder2 As outlook.MAPIFolder
Dim objFolder3 As outlook.MAPIFolder
Dim objFolder4 As outlook.MAPIFolder
Dim objFolder5 As outlook.MAPIFolder
Dim objFolder6 As outlook.MAPIFolder
Dim objFolder7 As outlook.MAPIFolder
Dim objFolder8 As outlook.MAPIFolder
Dim ctc As ContactItem
Dim Category As String

Set objOutlook = CreateObject("Outlook.Application")
Set objFolder = objOutlook.Session.GetDefaultFolder(OlDefaultFolders.olFolderContacts)
Set objFolder2 = objOutlook.Session.GetDefaultFolder(OlDefaultFolders.olFolderContacts).Folders("Test")
Set objFolder3 = objOutlook.Session.GetDefaultFolder(OlDefaultFolders.olFolderContacts).Folders("Family")
Set objFolder4 = objOutlook.Session.GetDefaultFolder(OlDefaultFolders.olFolderContacts).Folders("Friends")
Set objFolder5 = objOutlook.Session.GetDefaultFolder(OlDefaultFolders.olFolderContacts).Folders("Test2")
Set objFolder6 = objOutlook.Session.GetDefaultFolder(OlDefaultFolders.olFolderContacts).Folders("Test3")
Set objFolder7 = objOutlook.Session.GetDefaultFolder(OlDefaultFolders.olFolderContacts).Folders("Test").Folders("SubTest")
Set objFolder8 = objOutlook.Session.GetDefaultFolder(OlDefaultFolders.olFolderContacts).Folders("Test").Folders("SubTest2")

Category = Me.ddlCategories.Text

Me.ddlContacts.Clear

For Each ctc In objFolder.items
If ctc.Categories = Category Then
Me.ddlContacts.addItem ctc.FullName
End If
Next

For Each subFolder In objOutlook.Session.GetDefaultFolder(OlDefaultFolders.olFolderContacts).Folders
addItem subFolder, Category
Next

For Each subFolder In objOutlook.Session.GetDefaultFolder(OlDefaultFolders.olFolderContacts).Folders("Test").Folders
addItem subFolder, Category
Next


End Sub
Private Sub addItem(subFolder, categoriesName As String)
For Each ctc In subFolder.items
If ctc.Categories = categoriesName Then
Me.ddlContacts.addItem ctc.FullName
End If
Next
End Sub

Private Sub UserForm_Initialize()
Dim Category

For Each Category In Application.Session.Categories
Me.ddlCategories.addItem Category
Next
End Sub
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
You need to use a filter and search for the contact. If your goal to open the contact?

This should work - you'll need to pass the name in the userform to the macro as strFullname and may need to pass the folder to myContacts.

Public Sub FindContactChange()
Dim Selection As Selection
Dim currentItem As Object
Dim strFullname As String
Dim myContacts As Items
Dim myItem As ContactItem

' may need to get myContact from the userform
Set myContacts = Session.GetDefaultFolder(olFolderContacts).Items
On Error Resume Next

' get strFullname from the userform
Set myItem = myContacts.Find("[FullName]=" & Chr(34) & strFullname & Chr(34))
If TypeName(myItem) = "ContactItem" Then
If Not TypeName(myItem) = "Nothing" Then
' Match found
myItem.Display
End If
End If

Err.Clear
Set myItem = Nothing
Set myContacts = Nothing
Set objMail = Nothing
Set currentItem = Nothing
Set Selection = Nothing

End Sub
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
thank you so much....can you please tell me where to put the macro you just wrote down? That is what I don't understand where to put it.....thank you as i would love to try it!!
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
thank you so much....can you please tell me where to put the macro you just wrote down? That is what I don't understand where to put it.....thank you as i would love to try it!!

And if this is added to the Userform code, is there anything to delete from my first code?
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
Any update tonight please?! I just need to know where do I put what you wrote in And if this is added to the Userform code, is there anything to delete from my first code?
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
It would go in the module. You need to pass the values from the user form selection to it.
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
thanks very much....I put it in a new module 38 and the Userform is Userform22.....so what do I add to both so when I run the the Module it does what needs to do thru the Userform 22......I used the code you gave me, but don't now how to connect the Module to the Userform......quick answer maybe???
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
To the Smart Woman!!! Here is the updated code for Userform22 that does not need a macro to run it and past in from it.....this code runs two comboxboxes....one is the list of categories and after clicking on a category, it opens up on the the other combobox the list contacts for that category from all subfolders and sub-subfolders......but for reason does not show the contacts in the Contact folder re the categories...but other than that is shows all are llnks to the contact themselves....so what to fix so shows the contacts from the Contact folder....here it is in the next post:
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
Private Sub ddlCategories_Change()
Dim objOutlook As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim objFolder As Outlook.MAPIFolder
Dim ctc As ContactItem
Dim FolderName As String
Dim fldr As Folder
Dim flder As Outlook.Folder
Dim myContacts As Outlook.items
Dim Category As String
Category = Me.ddlCategories.Text

Set objOutlook = CreateObject("Outlook.Application")
Set objFolder = objOutlook.Session.GetDefaultFolder(OlDefaultFolders.olFolderContacts)

Me.ddlContacts.Clear

If objFolder.Folders.Count > 0 Then
For Each fldr In objFolder.Folders
Set myContacts = fldr.items.Restrict("[Categories] = '" & Category & "'")
If myContacts.Count > 0 Then
myContacts.Sort "[Fullname]", False

For Each ctc In myContacts
Me.ddlContacts.addItem ctc.FullName
Next
End If

For Each flder In fldr.Folders
Set myContacts = flder.items.Restrict("[Categories] = '" & Category & "'")
If myContacts.Count > 0 Then
myContacts.Sort "[Fullname]", False

For Each ctc In myContacts
Me.ddlContacts.addItem ctc.FullName
Next
End If

Next
Next
End If

End Sub

Private Sub UserForm_Initialize()
'The loads the Outlook userform and populates the combobox of contact folders.

Dim objOutlook As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim objFolder As Outlook.MAPIFolder
Dim Category
Set objOutlook = CreateObject("Outlook.Application")

For Each Category In Application.Session.Categories
Me.ddlCategories.addItem Category
Next




End Sub

Private Sub ddlContacts_Change()
'This opens the contact form for the contact selected.
Dim objOutlook As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim ctcItems As Outlook.items
Dim ctc As ContactItem
Dim objFolder As Outlook.MAPIFolder
Dim ctcFolder As Outlook.MAPIFolder
Dim FolderName As String
Dim ContactName As String
Dim FoundFolder As Outlook.Folder

Set objOutlook = CreateObject("Outlook.Application")
Set objFolder = objOutlook.Session.GetDefaultFolder(OlDefaultFolders.olFolderContacts)

ContactName = Me.ddlContacts.Text

If objFolder.Folders.Count > 0 Then
For Each fldr In objFolder.Folders
Set ctcItems = fldr.items.Restrict("[FullName] = '" & ContactName & "'")
If ctcItems.Count > 0 Then
Me.Hide
For Each ctc In ctcItems
ctc.Display
Next
Exit Sub
Else
For Each flder In fldr.Folders
Set ctcItems = flder.items.Restrict("[FullName] = '" & ContactName & "'")
If ctcItems.Count > 0 Then
Me.Hide
For Each ctc In ctcItems
ctc.Display
Next
Exit Sub
End If
Next
End If
Next
End If

End Sub

Private Function FullFolderName(ByVal FolderName As String) As Outlook.Folder


End Function
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
Just in case, you see my questions above just in case you know what to upgrade....and also, if you see the code area that sorts the contacts by their name...which is line: myContacts.Sort "[Fullname]", False what can I add and where to add it to sort the names of the Categories on an alphebetical basis....?

Very happy to hear back soon....as the category area is even faster for organizing things...
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
Got it! Any other updates re the other areas .so what to fix so shows the contacts from the Contact folder....and not just the subfolders?
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
Got it! Any other updates re the other areas .so what to fix so shows the contacts from the Contact folder....and not just the subfolders?
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
Still waiting for the Smart Woman!!
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
For Each fldr In objFolder.Folders - the default folder is not an object in itself. Use the entire mailbox instead. As long as you are restricting it to contact items, that is all it will return.
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
Thank you as usual!!

Please write down the specific code and tell me what to replace to.
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
Still waiting for the Smart Woman to give me the code, wherr to put it, and what delete!'
 
Status
Not open for further replies.
Thread starter Similar threads Forum Replies Date
A Outlook Userform Size Outlook VBA and Custom Forms 2
N Activity Tracking with Userform Outlook VBA and Custom Forms 4
D Next Available Meeting with Userform Variables Outlook VBA and Custom Forms 1
A Populate Excel from Outlook Userform Outlook VBA and Custom Forms 3
B Insert Hyperlinks for attachments in Userform Outlook VBA and Custom Forms 5
D Change sender name outlook vba 2010 Custom Userform Outlook VBA and Custom Forms 1
A Open CHM file from VBA Userform Outlook VBA and Custom Forms 4
L Outlook 2007 - Userform Using Outlook 2
A Focus on the userform Outlook VBA and Custom Forms 15
F Outlook 2010 - outlook userform and combo boxes Using Outlook 9
L Userform Field Month and Date. Using Outlook 19
witzker insert Date & Time (HH:mm) no (ss) in userform Using Outlook 6
A insert Date & Time in userform Using Outlook 3
X VBA: Confused with variables between ThisOutlookSession and UserForm Using Outlook 1
M Progrescreas Bar in Outlook UserForm Using Outlook 1
C UserForm and ordering variables Outlook VBA and Custom Forms 3
J userform combobox Outlook VBA and Custom Forms 1
R combobox list in userform Outlook VBA and Custom Forms 1
B Userform Outlook VBA and Custom Forms 5
W Using Excel UserForm from Open Workbook in Outlook VBA Outlook VBA and Custom Forms 5
P userform in VBAProject.otm not working Outlook VBA and Custom Forms 1
S Skype for business meeting vba code Outlook VBA and Custom Forms 1
R Expand VBA Permanent Delete Code Outlook VBA and Custom Forms 6
B Outlook Business Contact Manager with SQL to Excel, User Defined Fields in BCM don't sync in SQL. Can I use VBA code to copy 1 field to another? BCM (Business Contact Manager) 0
A VBA Code in Outlook disappears after first use Outlook VBA and Custom Forms 1
Alex Cotton "invalid or unqualified reference" on code that should work Outlook VBA and Custom Forms 5
F VBA to ensure a code is entered in Subject title Outlook VBA and Custom Forms 1
Z Outlook Custom Form: Adding Dropdown(Project Code) at the end of subject Outlook VBA and Custom Forms 0
D Any updates or fixes that would make this code stop working just moving emails to another folder Outlook VBA and Custom Forms 1
N Open & Save VBAProject.Otm using VBA Code Outlook VBA and Custom Forms 1
M error code 0x8DE00006 Using Outlook 1
R VBA Code to permanently delete selected email Outlook VBA and Custom Forms 10
dyny723 Outlook 2016: Code to link a contact to emails received from that contact Outlook VBA and Custom Forms 1
D Command Button code will not execute. Any suggestions Please. Outlook VBA and Custom Forms 2
V VB script code to save a specific email attachment from a given email Outlook VBA and Custom Forms 14
J Custom form code doesn't run Outlook VBA and Custom Forms 2
M code to move selected Outlook contacts to another folder Using Outlook 3
E Outlook Form - Voting Responses Not Auto Processing If Form Contains Any Code Outlook VBA and Custom Forms 0
C Need VBA code to automatically save message outside outlook and add date Outlook VBA and Custom Forms 1
S Problem running Command button code Outlook VBA and Custom Forms 2
D Help with code to move mail on receipt to another folder based on time received Outlook VBA and Custom Forms 2
C Color Code New Calendar Items Using Outlook 2
S VBA Code to move mail items from search folder to inbox subfolder Outlook VBA and Custom Forms 4
B Automation error running VB macro code Outlook VBA and Custom Forms 8
S my vbscript button1_click code works on appointment created but not on opening an existing apntmn Outlook VBA and Custom Forms 16
M regarding the Create Contacts From Messages code Using Outlook 8
J Outlook 2010 VBScript editor does not run code at all Outlook VBA and Custom Forms 0
B VBA Code to create appointment from email Outlook VBA and Custom Forms 1
D VBA Code to strip Subject Line when replying or forwarding Using Outlook 3
L Outlook 2007 Contact Form Code Not Working Using Outlook 20
Similar threads


















































Top