UserForm Code For Contact Links

Status
Not open for further replies.

LMS

Senior Member
Outlook version
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
 
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
 
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!!
 
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?
 
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?
 
It would go in the module. You need to pass the values from the user form selection to it.
 
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???
 
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:
 
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
 
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...
 
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?
 
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?
 
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.
 
Thank you as usual!!

Please write down the specific code and tell me what to replace to.
 
Still waiting for the Smart Woman to give me the code, wherr to put it, and what delete!'
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
R Adding Userform Dropdown List items from names of subfolders on network drive Outlook VBA and Custom Forms 10
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
P How to get a QR code for automatic signin with Outlook for iOS Using Outlook 5
D Outlook 2021 Using vba code to delete all my spamfolders not only the default one. Outlook VBA and Custom Forms 0
F Color code certain INBOX emails Using Outlook 2
K vba code to auto download email into a specific folder in local hard disk as and when any new email arrives in Inbox/subfolder Outlook VBA and Custom Forms 0
J Want to create a button on the nav bar (module add-in) to run code Outlook VBA and Custom Forms 2
H Preventing the 'email address fetch from Exchange' crashing email reading code Exchange Server Administration 0
C Code to move mail with certain attachment name? Does Not work Outlook VBA and Custom Forms 3
Aussie Outlook 365 Rule runs manually but returns the error code "an unexpected error has occurred" when incoming mail arrives Using Outlook 1
S Need code to allow defined starting folder and selection from there to drill down Outlook VBA and Custom Forms 10
D VBA code to select a signature from the signatures list Outlook VBA and Custom Forms 3
S HTML Code Embedded in String Within Open Outlook Email Preventing Replace(Application.ActiveInspector.CurrentItem.HTMLBody From Working Outlook VBA and Custom Forms 4
P Color Code or highlight folders in Outlook 2016 Using Outlook 2
N Please advise code received new mail Using Outlook 0
B Outlook 2016 Unable to view images or logos on the outlook 2016 emails the same html code works well when i use outlook 2010 Using Outlook 0
S Excel vba code to manage outlook web app Using Outlook 10
S Outlook VBA How to adapt this code for using in a different Mail Inbox Outlook VBA and Custom Forms 0
S Add VBA save code Using Outlook 0
C Auto Run VBA Code on new email Outlook VBA and Custom Forms 1
Witzker Pls help to change the code for inserting date in Ol contact body Outlook VBA and Custom Forms 5
I Outlook 2003 shows html code when To: field is empty Using Outlook 7
F VBA code to dock Styles whenever I write or edit an email Outlook VBA and Custom Forms 0
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

Similar threads

Back
Top