jana
asked on
Instruction to open a Contact selected in a List Box in Outlook 2010 via VBA
EE has helped us with a Macro that searches the Contacts in Microsoft Outlook 2010. We have a routine that fills a List Box and displays at the end of the search, what has been found.
We are trying to find the instruction that when we set the control that user double-click on the line with the List Box, it would open THAT Contact record.
Please advice on the proper way to go about this.
We are trying to find the instruction that when we set the control that user double-click on the line with the List Box, it would open THAT Contact record.
Please advice on the proper way to go about this.
ASKER
Hi,
when you say "information is written to an Access table for display in the listbox", do you mean Microsoft Access apps?
when you say "information is written to an Access table for display in the listbox", do you mean Microsoft Access apps?
I meant that data from Outlook contacts was written to an Access table, where it could be used as the row source of the listbox, and thus could be used to select a contact and open it, as in the code I posted. Here is some code that writes Outlook data to an Access table:
This procedure is from the sample database for my Working with Outlook ebook, which describes many ways of exchanging data between Access and Outlook. It is available from Office Watch.
Public Sub ImportStandardContacts()
'Created by Helen Feddema 17-Dec-2011
'Last modified by Helen Feddema 25-Jan-2012
On Error GoTo ErrorHandler
Set rst = CurrentDb.OpenRecordset("tblContacts", _
dbOpenDynaset)
Set appOutlook = GetObject(, "Outlook.Application")
Set nms = appOutlook.GetNamespace("MAPI")
SelectContactsFolder:
On Error Resume Next
Set fldContacts = nms.PickFolder
If fldContacts Is Nothing Then
GoTo ErrorHandlerExit
ElseIf fldContacts.DefaultItemType <> olContactItem Then
strPrompt = "Please select a Contacts folder"
strTitle = "Select folder"
MsgBox prompt:=strPrompt, _
buttons:=vbExclamation + vbOKOnly, _
Title:=strTitle
GoTo SelectContactsFolder
End If
On Error GoTo ErrorHandler
strTitle = "Question"
strPrompt = "Automatically overwrite duplicates (Yes) or ask for each duplicate (No)?"
intResult = MsgBox(prompt:=strPrompt, _
buttons:=vbQuestion + vbYesNo, _
Title:=strTitle)
intNewCount = 0
intUpdateCount = 0
For Each itm In fldContacts.Items
If itm.Class = olContact Then
Set con = itm
'Determine whether contact is already in tblContacts
strFirstName = con.FirstName
strLastName = con.LastName
strFullName = strFirstName & " " & strLastName
strSearch = "[FirstName] = " & Chr(39) & strFirstName _
& Chr(39) & " And [LastName] = " & Chr(39) _
& strLastName & Chr(39)
Debug.Print "Search string: " & strSearch
rst.FindFirst strSearch
If rst.NoMatch = True Then
'Add contact as a new record
rst.AddNew
rst![FirstName] = con.FirstName
rst![LastName] = con.LastName
rst![Salutation] = con.NickName
rst![StreetAddress] = con.BusinessAddressStreet
rst![City] = con.BusinessAddressCity
rst![StateOrProvince] = con.BusinessAddressState
rst![PostalCode] = con.BusinessAddressPostalCode
rst![Country] = con.BusinessAddressCountry
rst![CompanyName] = con.CompanyName
rst![JobTitle] = con.JobTitle
rst![WorkPhone] = con.BusinessTelephoneNumber
rst![MobilePhone] = con.MobileTelephoneNumber
rst![FaxNumber] = con.BusinessFaxNumber
rst![EmailName] = con.Email1Address
rst.Update
intNewCount = intNewCount + 1
Else
If intResult = vbYes Then
rst.Edit
rst![FirstName] = con.FirstName
rst![LastName] = con.LastName
rst![Salutation] = con.NickName
rst![StreetAddress] = con.BusinessAddressStreet
rst![City] = con.BusinessAddressCity
rst![StateOrProvince] = con.BusinessAddressState
rst![PostalCode] = con.BusinessAddressPostalCode
rst![Country] = con.BusinessAddressCountry
rst![CompanyName] = con.CompanyName
rst![JobTitle] = con.JobTitle
rst![WorkPhone] = con.BusinessTelephoneNumber
rst![MobilePhone] = con.MobileTelephoneNumber
rst![FaxNumber] = con.BusinessFaxNumber
rst![EmailName] = con.Email1Address
rst.Update
intUpdateCount = intUpdateCount + 1
ElseIf intResult = vbNo Then
strTitle = "Duplicate contact"
strPrompt = strFullName & " is already in tblContacts; " _
& "overwrite record with data from Outlook?"
intReturn = MsgBox(prompt:=strPrompt, _
buttons:=vbQuestion + vbYesNo, _
Title:=strTitle)
If intReturn = vbYes Then
rst.Edit
rst![FirstName] = con.FirstName
rst![LastName] = con.LastName
rst![Salutation] = con.NickName
rst![StreetAddress] = con.BusinessAddressStreet
rst![City] = con.BusinessAddressCity
rst![StateOrProvince] = con.BusinessAddressState
rst![PostalCode] = con.BusinessAddressPostalCode
rst![Country] = con.BusinessAddressCountry
rst![CompanyName] = con.CompanyName
rst![JobTitle] = con.JobTitle
rst![WorkPhone] = con.BusinessTelephoneNumber
rst![MobilePhone] = con.MobileTelephoneNumber
rst![FaxNumber] = con.BusinessFaxNumber
rst![EmailName] = con.Email1Address
rst.Update
intUpdateCount = intUpdateCount + 1
Else
GoTo NextItem
End If
End If
End If
End If
NextItem:
Next itm
Debug.Print "New count: " & intNewCount
Debug.Print "Update count: " & intUpdateCount
If intNewCount = 0 Then
If intUpdateCount = 0 Then
strPrompt = "No contacts added or updated"
ElseIf intUpdateCount = 1 Then
strPrompt = "No contacts added; 1 contact updated"
ElseIf intUpdateCount > 1 Then
strPrompt = "No contacts added; " & CStr(intUpdateCount) _
& " contacts updated"
End If
ElseIf intNewCount = 1 Then
If intUpdateCount = 1 Then
strPrompt = "1 contact added; 1 contact updated"
ElseIf intUpdateCount > 1 Then
strPrompt = "1 contact added; " & CStr(intUpdateCount) _
& " contacts updated"
End If
ElseIf intNewCount > 1 Then
If intUpdateCount = 1 Then
strPrompt = CStr(intNewCount) & " contacts added; " _
& "1 contact updated"
ElseIf intUpdateCount > 1 Then
strPrompt = CStr(intNewCount) & " contacts added; " _
& CStr(intUpdateCount) & " contacts updated"
End If
End If
strTitle = "Import done"
MsgBox prompt:=strPrompt, _
buttons:=vbInformation + vbOKOnly, _
Title:=strTitle
ErrorHandlerExit:
Exit Sub
ErrorHandler:
'Outlook is not running; open Outlook with CreateObject
If Err.Number = 429 Then
Set appOutlook = CreateObject("Outlook.Application")
Resume Next
Else
MsgBox "Error No: " & Err.Number _
& " in ImportStandardContacts procedure; " _
& "Description: " & Err.Description
Resume ErrorHandlerExit
End If
End Sub
This procedure is from the sample database for my Working with Outlook ebook, which describes many ways of exchanging data between Access and Outlook. It is available from Office Watch.
ASKER
Understood.
The information is not written to an Access table. The data we we extracted via VBA is within Outlook data. That said, here is the portion of vba we are using write the search result to the listbox:
As you can see, the line "SearchContactsBody.lstCont actsBody.A ddItem currentContact.FullName'" is where we fill the ListBox.
The line "SearchContactsBody.Show" display the form with ListBox contents and passes control to that Form.
What we are trying to do is if a user double-click on a specific line, to open the contact for the user.
(hope we gave a clearer view of what we are trying to do)
The information is not written to an Access table. The data we we extracted via VBA is within Outlook data. That said, here is the portion of vba we are using write the search result to the listbox:
If SearchContactBody > "" Then
Set ContactFolder = GetFolderPath("\\iCloud\Contacts")
For Each currentItem In ContactFolder.Items
If (currentItem.Class = olContact) Then
Set currentContact = currentItem
If InStr(1, currentContact.Body, SearchContactBody, vbTextCompare) Then
SearchContactsBody.lstContactsBody.AddItem currentContact.FullName
End If
End If
Next
SearchContactsBody.Show
As you can see, the line "SearchContactsBody.lstCont
The line "SearchContactsBody.Show" display the form with ListBox contents and passes control to that Form.
What we are trying to do is if a user double-click on a specific line, to open the contact for the user.
(hope we gave a clearer view of what we are trying to do)
Since you are adding the FullName to the listbox, then that is what you can use to open the contact -- just use FullName instead of concatenating FirstName and LastName; here is the modified code:
Public Sub OpenAContact()
'Created by Helen Feddema 28-Apr-2015
'Last modified by Helen Feddema 28-Apr-2015
On Error GoTo ErrorHandler
Dim appOutlook As Outlook.Application
Dim con As Outlook.ContactItem
Dim lst As Access.ListBox
Dim nms As Outlook.NameSpace
Dim fldContacts As Outlook.Folder
Dim strFilter As String
Dim strFullName As String
Dim varTest As Variant
Set appOutlook = GetObject(, "Outlook.Application")
'Get data from selected item in listbox -- modify as needed
'for your form
Set lst = Forms![frmTest]![lstContacts]
strFullName = Nz(lst.Column(0))
Debug.Print "Full name: " & strFullName
SelectContactsFolder:
Set nms = appOutlook.GetNamespace("MAPI")
Set fldContacts = nms.PickFolder
If fldContacts Is Nothing Then
GoTo ErrorHandlerExit
ElseIf fldContacts.DefaultItemType <> olContactItem Then
strPrompt = "Please select a Contact folder"
strTitle = "Select folder"
MsgBox prompt:=strPrompt, _
buttons:=vbExclamation + vbOKOnly, _
Title:=strTitle
GoTo SelectContactsFolder
End If
'Try finding contact by FullName:
strFilter = "[FullName] = " & Chr(39) & strFullName & Chr(39)
Debug.Print "Filter string: " & strFilter
Set varTest = fldContacts.Items.Find(strFilter)
If IsNull(varTest) = True Then
strTitle = "Can't find contact"
strPrompt = strFullName _
& " is not in " & fldContacts.Name & "; exiting"
MsgBox prompt:=strPrompt, _
buttons:=vbExclamation + vbOKOnly, _
Title:=strTitle
GoTo ErrorHandlerExit
Else
Set con = fldContacts.Items(strFullName)
End If
DisplayContact:
con.Display
ErrorHandlerExit:
Set appOutlook = Nothing
Set con = Nothing
Exit Sub
ErrorHandler:
'Outlook is not running; open Outlook with CreateObject
If Err.Number = 429 Then
Set appOutlook = CreateObject("Outlook.Application")
Resume
Else
MsgBox "Error No: " & Err.Number _
& " in OpenAContact procedure; " _
& "Description: " & Err.Description
Resume ErrorHandlerExit
End If
End Sub
ASKER
Ok will try.
ASKER
Hi, sorry for the delay but we had a problem with our ms office...
ran your code and it's pointing to access (see pix):
We notice you have to select folder and finds, please note that we already have all the contacts in the listbox. We need to double-click the line with the listbox, and have the Contact Window open for edit of that line clicked.
We noticed that these 2 lines:
may be the instruction needed for what we want, but we seem to be missing something.
ran your code and it's pointing to access (see pix):
We notice you have to select folder and finds, please note that we already have all the contacts in the listbox. We need to double-click the line with the listbox, and have the Contact Window open for edit of that line clicked.
We noticed that these 2 lines:
Dim con As Outlook.ContactItem
Set con = fldContacts.Items(strFullName)
may be the instruction needed for what we want, but we seem to be missing something.
I was assuming that you were running the code from Access, but maybe not. If it is running from an Outlook item of some sort, that would require VBS code, and a number of changes in the syntax. It if is running from an Outlook UserForm, that would use VBA (a lot easier to work with than VBS on an Outlook form), but still some modifications would be needed. Let me know where you are running this code, and I can make some modifications.
ASKER
Vba macro in outlook 2010.
We already have the list box of running; it gets filled by another macro that searches contacts. What we are missing is opening the contact.
What instruction opens up the contact so we can make it pop out and have the user edit when clicking it from within the list is?
We already have the list box of running; it gets filled by another macro that searches contacts. What we are missing is opening the contact.
What instruction opens up the contact so we can make it pop out and have the user edit when clicking it from within the list is?
Where is the listbox located? On an Outlook custom form, a VBA UserForm, or an Access form? It can work any way, but It makes a difference for the coding.
ASKER
In an Outlook custom form, a VBA UserForm.
ASKER
Please note, to give you an example of what we are trying to accomplish.
Below is the form we have (a display of search results):
We want, as per this example, if the user double-click on "JEFFERSON PILOT FINANCIAL", they get the contact windows as seen below:
Hence, the user selects from the LISTBOX and the contact is displayed for editing.
Hope this helps.
Below is the form we have (a display of search results):
We want, as per this example, if the user double-click on "JEFFERSON PILOT FINANCIAL", they get the contact windows as seen below:
Hence, the user selects from the LISTBOX and the contact is displayed for editing.
Hope this helps.
This code will do it, with a FolderPicker dialog to select the appropriate Contacts folder (there is a commented-out line to use the default folder, if that is what you need, or you can hard-code any Contacts folder).
Private Sub lstContacts_DblClick(Cancel As Integer)
'Created by Helen Feddema 3-Jun-2016
'Last modified by Helen Feddema 3-Jun-2016
On Error GoTo ErrorHandler
Dim appOutlook As Outlook.Application
Dim con As Outlook.ContactItem
Dim lst As Access.ListBox
Dim nms As Outlook.NameSpace
Dim fldContacts As Outlook.Folder
Dim strFilter As String
Dim strFullName As String
Dim varTest As Variant
Set appOutlook = GetObject(, "Outlook.Application")
'Get data from selected item in listbox -- modify as needed
'for your form
Set lst = Me![lstContacts]
strFullName = Nz(lst.Column(0))
Debug.Print "Full name: " & strFullName
'Set fldContacts = nms.GetDefaultFolder(olFolderContacts)
SelectContactsFolder:
Set nms = appOutlook.GetNamespace("MAPI")
Set fldContacts = nms.PickFolder
If fldContacts Is Nothing Then
GoTo ErrorHandlerExit
ElseIf fldContacts.DefaultItemType <> olContactItem Then
strPrompt = "Please select a Contact folder"
strTitle = "Select folder"
MsgBox prompt:=strPrompt, _
buttons:=vbExclamation + vbOKOnly, _
Title:=strTitle
GoTo SelectContactsFolder
End If
'Try finding contact by FullName:
strFilter = "[FullName] = " & Chr(39) & strFullName & Chr(39)
Debug.Print "Filter string: " & strFilter
Set varTest = fldContacts.Items.Find(strFilter)
If IsNull(varTest) = True Then
strTitle = "Can't find contact"
strPrompt = strFullName _
& " is not in " & fldContacts.Name & "; exiting"
MsgBox prompt:=strPrompt, _
buttons:=vbExclamation + vbOKOnly, _
Title:=strTitle
GoTo ErrorHandlerExit
Else
Set con = fldContacts.Items(strFullName)
End If
DisplayContact:
con.Display
ErrorHandlerExit:
Set appOutlook = Nothing
Set con = Nothing
Exit Sub
ErrorHandler:
'Outlook is not running; open Outlook with CreateObject
If Err.Number = 429 Then
Set appOutlook = CreateObject("Outlook.Application")
Resume
Else
MsgBox "Error No: " & Err.Number _
& " in OpenAContact procedure; " _
& "Description: " & Err.Description
Resume ErrorHandlerExit
End If
End Sub
ASKER
got an error...
Note:
In order to give EE a scope of what we are working with, the following script is the routine that fills the userform 'SearchContactsBody''s ListBox called 'lstContactsBody'.
The userform perse is no code (we still woking on how to open the selected contact with the listbox 'lstContactsBody').
Hope this helps you help us.
Note (2):
We are looking for how to use
ContactItem.EntryID and ContactItem.Parent.StoreID in order to identify prior display the contact window.
Are we in the right direction? We missing anything?
Note:
In order to give EE a scope of what we are working with, the following script is the routine that fills the userform 'SearchContactsBody''s ListBox called 'lstContactsBody'.
Public Sub aSearchContacts()
'*********** SEARCH CONTACTS ROUTINES
Dim ContactFolder As Outlook.Folder
Dim currentItem As Object
Dim currentContact As ContactItem
Dim SearchContactBody As String
Dim x As Integer
x = 0 'Counter
SearchContactsBody.lstContactsBody.Clear
'Ask for what to search
SearchContactBody = InputBox("What are you looking for?", "Search Within Contact Body")
If SearchContactBody > "" Then
Set ContactFolder = GetFolderPath("\\iCloud\Contacts")
For Each currentItem In ContactFolder.Items
If (currentItem.Class = olContact) Then
Set currentContact = currentItem
If InStr(1, currentContact.Body, SearchContactBody, vbTextCompare) Then
SearchContactsBody.lstContactsBody.AddItem UCase(currentContact.FullName)
x = x + 1
End If
End If
Next
SearchContactsBody.lblMessage1 = "Found '" & x & "' Contacts with: "
SearchContactsBody.lblMessage2 = Chr(34) & " " & SearchContactBody & " " & Chr(34)
SearchContactsBody.Show
End If
End Sub
The userform perse is no code (we still woking on how to open the selected contact with the listbox 'lstContactsBody').
Hope this helps you help us.
Note (2):
We are looking for how to use
ContactItem.EntryID and ContactItem.Parent.StoreID
Are we in the right direction? We missing anything?
ASKER
We also found this link trying top code it for our Outlook ... http://stackoverflow.com/questions/30918152/opening-outlook-address-book-from-excel
please advice.
please advice.
ASKER
Hey just ran into your site http://www.helenfeddema.com/Code%20Samples.htm
ASKER
We are looking for a way, a VBA script, where we can use an instruction or statement to open up the Contact window after being "double-clicks" on it selected within a ListBox.
For example, if we double-click on Jefferson Pilot (see below), we get the Contacts Windows to edit its. content
Note:
We have the code that fill our ListBox; see our entry on ID: 41634857 based on the recommendation on ID: 41634798 (we are getting an error)
Please advice on how to open up the windows of a Contact so we can edit it.
Thanx!
For example, if we double-click on Jefferson Pilot (see below), we get the Contacts Windows to edit its. content
Note:
We have the code that fill our ListBox; see our entry on ID: 41634857 based on the recommendation on ID: 41634798 (we are getting an error)
Please advice on how to open up the windows of a Contact so we can edit it.
Thanx!
This code will do it, provided that the listbox contains FullName values:
Public Sub OpenAContact()
'Created by Helen Feddema 28-Apr-2015
'Last modified by Helen Feddema 28-Apr-2015
On Error GoTo ErrorHandler
Dim appOutlook As Outlook.Application
Dim con As Outlook.ContactItem
Dim lst As Access.ListBox
Dim nms As Outlook.NameSpace
Dim fldContacts As Outlook.Folder
Dim strFilter As String
Dim strFullName As String
Dim varTest As Variant
Set appOutlook = GetObject(, "Outlook.Application")
'Get data from selected item in listbox -- modify as needed
'for your form
Set lst = Forms![frmTest]![lstContacts]
strFullName = Nz(lst.Column(0))
Debug.Print "Full name: " & strFullName
SelectContactsFolder:
Set nms = appOutlook.GetNamespace("MAPI")
Set fldContacts = nms.PickFolder
If fldContacts Is Nothing Then
GoTo ErrorHandlerExit
ElseIf fldContacts.DefaultItemType <> olContactItem Then
strPrompt = "Please select a Contact folder"
strTitle = "Select folder"
MsgBox prompt:=strPrompt, _
buttons:=vbExclamation + vbOKOnly, _
Title:=strTitle
GoTo SelectContactsFolder
End If
'Try finding contact by FullName:
strFilter = "[FullName] = " & Chr(39) & strFullName & Chr(39)
Debug.Print "Filter string: " & strFilter
Set varTest = fldContacts.Items.Find(strFilter)
If IsNull(varTest) = True Then
strTitle = "Can't find contact"
strPrompt = strFullName _
& " is not in " & fldContacts.Name & "; exiting"
MsgBox prompt:=strPrompt, _
buttons:=vbExclamation + vbOKOnly, _
Title:=strTitle
GoTo ErrorHandlerExit
Else
Set con = fldContacts.Items(strFullName)
End If
DisplayContact:
con.Display
ErrorHandlerExit:
Set appOutlook = Nothing
Set con = Nothing
Exit Sub
ErrorHandler:
'Outlook is not running; open Outlook with CreateObject
If Err.Number = 429 Then
Set appOutlook = CreateObject("Outlook.Application")
Resume
Else
MsgBox "Error No: " & Err.Number _
& " in OpenAContact procedure; " _
& "Description: " & Err.Description
Resume ErrorHandlerExit
End If
End Sub
ASKER
Sorry for the delay.
For some reason we are projecting that we are using MS Access and you keep including this. In your code you again included Dim lst As Access.ListBox and again we get a 'Compile error: User-defined type not defined' when running (same error as in 3 weeks ago, see i]ID: 41634857[/i]).
In your entry ID: 41632216 you thought it was code from Access, and in the next entry we responded it Outlook.
For some reason we are projecting that we are using MS Access and you keep including this. In your code you again included Dim lst As Access.ListBox and again we get a 'Compile error: User-defined type not defined' when running (same error as in 3 weeks ago, see i]ID: 41634857[/i]).
In your entry ID: 41632216 you thought it was code from Access, and in the next entry we responded it Outlook.
A list box on an Outlook form, or a VBA Userform? Let me know which -- the syntax is different, and there is no ItemsSelected collection for either of those form types.
ASKER
VBA form.
ASKER
Went thru your code and maybe this can help you help us.
We found 2 lines that may represent what we are looking for:
Set con = fldContacts.Items(strFullN ame) = we assume this line will have the Contact's full name to display
con.Display = display or opens up the said Contact set in 'con '
If this is the case, that is what we are looking for. The instruction that tells VBA to open up a specific Contact.
We modified your line to get a specific Contact, instead of using the 'strFullName' variable, but gives an error.
We hope we have expressed our need.
Thanx in advance.
We found 2 lines that may represent what we are looking for:
Set con = fldContacts.Items(strFullN
con.Display = display or opens up the said Contact set in 'con '
If this is the case, that is what we are looking for. The instruction that tells VBA to open up a specific Contact.
We modified your line to get a specific Contact, instead of using the 'strFullName' variable, but gives an error.
We hope we have expressed our need.
Thanx in advance.
I will do some testing on a Userform tomorrow morning.
If you could upload the frm and frx files, I could modify your code directly.
ASKER
Sure!
ASKER
Here they go!
simple script.
On the routine 'Private Sub lstContactsBody_DblClick(B yVal Cancel As MSForms.ReturnBoolean)', that's where the "double-click" action that will fire up to "open " the selected or "double-clicked" data.
The list is filled with "FullName" of the contacts.
Hope this helps you help us!
Thanx again!
SearchContactsBody.frm
SearchContactsBody.frx
simple script.
On the routine 'Private Sub lstContactsBody_DblClick(B
The list is filled with "FullName" of the contacts.
Hope this helps you help us!
Thanx again!
SearchContactsBody.frm
SearchContactsBody.frx
I was able to download the frx file, but not the frm (it opened as code in Notepad). Can you zip ithe files and upload the zip?
ASKER
FRM are exported as text. We actually backup all our VBA via the macro screen by using the "export" option. The FRX are in some unreadable form or binary (don't know) and the FRM has always been in text or ascii.
ASKER
The UserForm is a simple Windows; just a ListBox no buttons. If you have problem with the one we sent, create one and we can base it from there.
When I export a Userform (from the VBA window) it saves both the frm and frx files, which can then be imported into a VBA project. I will make a simple Userform with a listbox containing contacts and see what I can do with it.
I made an Outlook UserForm, with some code on the Initialize event to fill a listbox with FullName values, and a command button to open the selected contact -- it works fine on my system:
Private Sub cmdOpenContact_Click()
'Created by Helen Feddema 26-Jun-2015
'Last modified by Helen Feddema 26-Jun-2015
On Error GoTo ErrorHandler
Set lst = Me.lstContacts
strFullName = lst.Value
Set nms = Application.GetNamespace("MAPI")
Set fld = nms.GetDefaultFolder(olFolderContacts)
Set con = fld.Items(strFullName)
Me.Hide
con.Display
ErrorHandlerExit:
Exit Sub
ErrorHandler:
MsgBox "Error No: " & Err.Number _
& " in cmdOpenContact_Click procedure; " _
& "Description: " & Err.Description
Resume ErrorHandlerExit
End Sub
Private Sub UserForm_Initialize()
'Created by Helen Feddema 26-Jun-2015
'Last modified by Helen Feddema 26-Jun-2015
On Error GoTo ErrorHandler
Set nms = Application.GetNamespace("MAPI")
Set fld = nms.GetDefaultFolder(olFolderContacts)
Set itms = fld.Items
Set lst = Me.lstContacts
intCount = 0
For Each itm In itms
If intCount = 10 Then
GoTo ErrorHandlerExit
Else
strFullName = itm.FullName
Debug.Print "Full name: " & strFullName
If strFullName <> "" Then
lst.AddItem strFullName
intCount = intCount + 1
End If
End If
Next itm
ErrorHandlerExit:
Exit Sub
ErrorHandler:
MsgBox "Error No: " & Err.Number _
& " in frmOpenContact Initialize procedure; " _
& "Description: " & Err.Description
Resume ErrorHandlerExit
End Sub
ASKER
Yes!!!! That is exactly what we have been looking for, an instructiosn(s) to"open the selected contact"!!!!
Ok we are heading back to test it!!!
Thanx!!!
Ok we are heading back to test it!!!
Thanx!!!
The variables are dimensioned in the module's main Declarations section:
Private fld As Outlook.Folder
Private lst As MSForms.ListBox
Private strFullName As String
Private con As Outlook.ContactItem
Private intCount As Integer
Private itm As Object
Private itms As Outlook.Items
Private nms As Outlook.NameSpace
If your contacts are not in the default local Contacts folder, you will need to set a reference to the appropriate folder -- here is some boilerplate code:
'Declare namespace and folder variables
'VBS syntax
Dim nms
Dim fld
'VBA syntax
Dim nms As Outlook.NameSpace
Dim fld as Outlook.MAPIFolder
Set nms = Application.GetNameSpace("MAPI")
'Set reference to default Calendar folder
'VBS syntax
Set fld = nms.GetDefaultFolder(9)
Set fld = appOutlook.Session.GetDefaultFolder(9)
'VBA syntax
Set fld = nms.GetDefaultFolder(olFolderCalendar)
Set fld = appOutlook.Session.GetDefaultFolder(olFolderCalendar)
'Set reference to default Contacts folder
'VBS syntax
Set fld = nms.GetDefaultFolder(10)
Set fld = appOutlook.Session.GetDefaultFolder(10)
'VBA syntax
Set fld = nms.GetDefaultFolder(olFolderContacts)
Set fld = appOutlook.Session.GetDefaultFolder(olFolderContacts)
'Set reference to default Deleted Items folder
'VBS syntax
Set fld = nms.GetDefaultFolder(3)
'VBA syntax
Set fld = nms.GetDefaultFolder(olFolderDeletedItems)
'Set reference to default Drafts folder
'VBS syntax
Set fld = nms.GetDefaultFolder(16)
'VBA syntax
Set fld = nms.GetDefaultFolder(olFolderDrafts)
'Set reference to default Inbox folder
'VBS syntax
Set fld = nms.GetDefaultFolder(6)
'VBA syntax
Set fld = nms.GetDefaultFolder(olFolderInbox)
'Set reference to default Journal folder
'VBS syntax
Set fld = nms.GetDefaultFolder(11)
Set fld = appOutlook.Session.GetDefaultFolder(11)
'VBA syntax
Set fld = nms.GetDefaultFolder(olFolderJournal)
Set fld = appOutlook.Session.GetDefaultFolder(olFolderJournal)
'Set reference to default Notes folder
'VBS syntax
Set fld = nms.GetDefaultFolder(12)
'VBA syntax
Set fld = nms.GetDefaultFolder(olFolderNotes)
Set fld = appOutlook.Session.GetDefaultFolder(olFolderNotes)
'Set reference to default Outbox folder
'VBS syntax
Set fld = nms.GetDefaultFolder(4)
Set fld = appOutlook.Session.GetDefaultFolder(4)
'VBA syntax
Set fld = nms.GetDefaultFolder(olFolderOutbox)
Set fld = appOutlook.Session.GetDefaultFolder(olFolderOutbox)
'Set reference to default Sent Mail folder
'VBS syntax
Set fld = nms.GetDefaultFolder(5)
'VBA syntax
Set fld = nms.GetDefaultFolder(olFolderSentMail)
'Set reference to default Tasks folder
'VBS syntax
Set fld = nms.GetDefaultFolder(13)
Set fld = appOutlook.Session.GetDefaultFolder(13)
'VBA syntax
Set fld = nms.GetDefaultFolder(olFolderTasks)
Set fld = appOutlook.Session.GetDefaultFolder(olFolderTasks)
'Set reference to custom Personal folder:
Set fld = nms.Folders("Personal Folders").Folders("Custom Folder")
'Set reference to custom Public folder:
Set fld = nms.Folders("Public Folders").Folders("All Public Folders").Folders("Custom Folder")
Or
Set fld = nms.GetDefaultFolder(olPublicFoldersAllPublicFolders)
'Display the selected folder
fld.display
'Set reference to a folder under an Exchange mailbox
'VBA syntax
Set objOutlook = CreateObject("Outlook.Application")
'Set reference to Outlook Calendar folder in an Exchange mailbox
Set nms = objOutlook.GetNamespace("MAPI")
Set rcp = nms.CreateRecipient(strUserName)
'strUserName must be the name of a valid recipient mailbox on
'Exchange server
rcp.Resolve
If rcp.Resolved Then
Set fld = nms.GetSharedDefaultFolder _
(rcp, olFolderCalendar)
Else
MsgBox "Can't find a valid mailbox for " & strUserName _
& "; using default local calendar"
Set fld = nms.GetDefaultFolder(olFolderCalendar)
End If
'VBS syntax
'Set reference to Outlook Contacts folder in an Exchange mailbox
Set nms = Application.GetNamespace("MAPI")
strUserName = nms.CurrentUser
Set rcp = nms.CreateRecipient(strUserName)
'strUserName must be the name of a valid recipient mailbox on
'Exchange server
rcp.Resolve
If rcp.Resolved Then
Set fld = nms.GetSharedDefaultFolder(rcp, 10)
Else
MsgBox "Can't find a valid mailbox for " & strUserName _
& "; using default local Contacts folder"
Set fld = nms.GetDefaultFolder(10)
End If
ASKER
Or maybe send us your FRM and FRX since it's working at your end.
You can omit the declarations that were made in the form code Declarations section. I posted the files -- maybe you had the same problem l had when trying to download yours. The form just had a list box and a command button; I posted the code
Here is a zip with the files.
Open-Contact.zip
Open-Contact.zip
ASKER
Ok will try when we get to he office.
Question, we went thru your code in ID: 41675210, where exactly is the command that woul open up the Contact's window?
Question, we went thru your code in ID: 41675210, where exactly is the command that woul open up the Contact's window?
That would be con.Display, after setting the con variable to the appropriate ContactItem:
11: Set con = fld.Items(strFullName)
12: Me.Hide
13: con.Display
14:
The Me.Hide is needed because if the UserForm is open when you try to open the contact, you will get an error message about a dialog being open (one of many peculiarities about Outlook coding).
ASKER
Ok just got in!
Thanx will proceed!
Thanx will proceed!
ASKER
Found the cause.
In your entry ID: 41675210, line 4 and 5 there is no definition; lines not complete:
We deleted and then line 16 got an error:
In your entry ID: 41675210, line 4 and 5 there is no definition; lines not complete:
4: Dim nms
5: Dim fld
5: Dim fld
We deleted and then line 16 got an error:
16: Set fld = appOutlook.Session.GetDefa ultFolder( 9)
Those are the VBScript versions, used on Outlook forms. VBS does not support declaring variables of specific data types. You need the VBA versions of the folder syntax.
ASKER
We are not making a question, we are just identifying why the script in ID: 41675210 gave the error.
In ID: 41676714, there 3 lines that you say will display the Contact window.
We are missing how to declare the variable fld and con in our VBA in order for the these lines to work.
Please advice
In ID: 41676714, there 3 lines that you say will display the Contact window.
Set con = fld.Items(strFullName)
Me.Hide
con.Display
Me.Hide
con.Display
We are missing how to declare the variable fld and con in our VBA in order for the these lines to work.
Please advice
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Are your contacts in the default local Contacts folder? If not, then you need to modify the fld setting line, using one of the VBA alternates I posted earlier.
ASKER
yes
when i see the value in 'fld', it's the Contact folder that we use.
when i see the value in 'fld', it's the Contact folder that we use.
Is there a problem? Does the contact open?
ASKER
Yes there is a problem; beside that the contact is not being open, it's not being found.
As said in ID: 41682609, we are getting error "object could not be found" when it hits the line fld. The entry that follows, ID: 41682611, is to show you that there is valid data sent to that line.
Why is the instruction not finding the contact when in the "debug" it display that the "strFulname" has a valid contact full name?
As said in ID: 41682609, we are getting error "object could not be found" when it hits the line fld. The entry that follows, ID: 41682611, is to show you that there is valid data sent to that line.
Why is the instruction not finding the contact when in the "debug" it display that the "strFulname" has a valid contact full name?
I think I could figure this out in a few minutes if I could log in to your computer. If that is OK with you, I can send you a GoToAssist invitation -- just send me your email, and indicate a time to connect.
ASKER
That sounds great! Unfortunately, the PC, not only is on constant use but is not authorized for remote access.
Maybe, better yet, basing on your good intentions in helping us, one thing we could do is clean up the actual outlook PST, leaving just some test contact with the VBA scripts in place and send it to you. That way you will see what we see and get a better feel of the problem.
Could that help?
Maybe, better yet, basing on your good intentions in helping us, one thing we could do is clean up the actual outlook PST, leaving just some test contact with the VBA scripts in place and send it to you. That way you will see what we see and get a better feel of the problem.
Could that help?
Yes, it would help if I could install the PST (including your Contacts folder with a few entries), and the UserForm files as you have modified them.
ASKER
Yes!!! It will have the structure as is, UserForm, etc. and some entries.
Ok, we will get to work on that!
Thanx!
Ok, we will get to work on that!
Thanx!
Put them all into a zip file, as otherwise there would be the problem with the frm file not downloading.
ASKER
Yes!! Will do!
ASKER
Hi,
Unfortunately we haven't been able to get a copy of the Outlook 2010 PST since the PC is in constant use.
So we proceed with another computer that has Outlook 2007 and copied everything over along with your suggestion.
And guess what? It worked perfect!! It open the contact window!!
This tells us that it may be that it's not looking at the folder where out Contacts are.
Question:
Our contacts are in "\\iCloud\Contacts". Does the line 'Set fld = nms.GetDefaultFolder(olFol derContact s)' opens the folder "\\iCloud\Contacts"? or is there a modification to this line in order to read our Contact folder?
Unfortunately we haven't been able to get a copy of the Outlook 2010 PST since the PC is in constant use.
So we proceed with another computer that has Outlook 2007 and copied everything over along with your suggestion.
And guess what? It worked perfect!! It open the contact window!!
This tells us that it may be that it's not looking at the folder where out Contacts are.
Question:
Our contacts are in "\\iCloud\Contacts". Does the line 'Set fld = nms.GetDefaultFolder(olFol
That is what I thought. That is definitely not the default local Contacts folder. I am not sure how to reference the folder, but maybe using the PickFolder method would work. I will send you some code tomorrow morning.
That code with the syntax alternatives dates to way before stuff was stored in the Cloud.
ASKER
We think we have one. An EE helped us with one. Will look for it and send it top you maybe you can decipher how it was done.
ASKER
here it goes,
Routine that fills the ListBox (see 'GetFolderPath("\\iCloud\Co ntacts")'):
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------
Function GetFolderPath:
Hope this helps!
Routine that fills the ListBox (see 'GetFolderPath("\\iCloud\Co
--------------------------
Public Sub aSearchContacts()
'*********** SEARCH CONTACTS BODY AND FILLS LISTBOX
Dim ContactFolder As Outlook.Folder
Dim currentItem As Object
Dim currentContact As ContactItem
Dim SearchContactBody As String
Dim x As Integer
SearchContactsBody.lstContactsBody.Clear
SearchContactBody = InputBox("What are you looking for?", "Search Within Contact Body")
If SearchContactBody > "" Then
Set ContactFolder = GetFolderPath("\\iCloud\Contacts")
For Each currentItem In ContactFolder.Items
If (currentItem.Class = olContact) Then
Set currentContact = currentItem
If InStr(1, currentContact.Body, SearchContactBody, vbTextCompare) Then
SearchContactsBody.lstContactsBody.AddItem UCase(currentContact.FullName)
End If
End If
Next
End If
End Sub
Function GetFolderPath:
Function GetFolderPath(ByVal FolderPath As String) As Outlook.Folder
'*********** FUNCTION THAT SETS THE FOLDER TO SEARCH THE CONTACTS IN
Dim oFolder As Outlook.Folder
Dim FoldersArray As Variant
Dim i As Integer
On Error GoTo GetFolderPath_Error
If Left(FolderPath, 2) = "\\" Then
FolderPath = Right(FolderPath, Len(FolderPath) - 2)
End If
'Convert folderpath to array
FoldersArray = Split(FolderPath, "\")
Set oFolder = Application.Session.Folders.Item(FoldersArray(0))
If Not oFolder Is Nothing Then
For i = 1 To UBound(FoldersArray, 1)
Dim SubFolders As Outlook.Folders
Set SubFolders = oFolder.Folders
Set oFolder = SubFolders.Item(FoldersArray(i))
If oFolder Is Nothing Then
Set GetFolderPath = Nothing
End If
Next
End If
'Return the oFolder
Set GetFolderPath = oFolder
Exit Function
GetFolderPath_Error:
Set GetFolderPath = Nothing
Exit Function
End Function
Hope this helps!
I redid my Open Contact UserForm to use the PickFolder method to get a Contacts folder, then save its StoreID and EntryID to Noteitems, so they could be retrieved and used to set the Folder variable when opening the selected contact. If your code for setting the Folder variable works, you can substitute it for the PickFolder code.to set the fldContacts variable (I can't test your code directly because I don't have that Cloud folder).
Here is a zip with the modified UserForm files.
Open-Contact-UserForm-files.zip
Here is a zip with the modified UserForm files.
Open-Contact-UserForm-files.zip
ASKER
Ran thru your code. Having always to use PickFolder for selecting Contacts folder, when there is only one, will get us in trouble.
Noticed that in If fldContacts holds the Contact folder name (see pix below).
Can you make it to just place that value and don't have the user to have the folders always presented to them?
There has to be a way.
Noticed that in If fldContacts holds the Contact folder name (see pix below).
Can you make it to just place that value and don't have the user to have the folders always presented to them?
There has to be a way.
ASKER
HELP!!! Just saw 2 instructions that has ADD & DELETE! (see below)
What exactly are these 2 instruction executing in Outlook?
(anything that alters data we must account for)
(anything that alters data we must account for)
They are deleting the old NoteItems before creating new ones with the StoreID and EntryID values. You may not need these notes at all. You could use a public variable (pfldContacts) declared in the Declarations section of the code module, set it to your folder in the Initialize event procedure, and then use it in the cmdOpenContact event procedure. I like to use NoteItems because they stay around until you delete them. I originally developed this method for my Time & Expense Billing app, which uses custom Outlook JournalItems to record time and expenses, and creates Word invoice documents filled with the data from Outlook. The folders used by this app are selected in Word VBA, the IDs are saved to NoteItems, and then the folders are set in Outlook as needed, using the saved ID values from the notes.
It is Code Sample #29 on my Website:
http://www.helenfeddema.com/Files/code29.zip
Where is your aSearchContacts procedure called from? Is it in the UserForm's Initialize event?
It is Code Sample #29 on my Website:
http://www.helenfeddema.com/Files/code29.zip
Where is your aSearchContacts procedure called from? Is it in the UserForm's Initialize event?
ASKER
You mean you use Outlook notes to hold data? in this case StoreID and EntryID values?
ASKER
Just re-read your entry, you use Outlook notes to hold temp data.
Ok understood.
Going back on our entry ID: 41686229, the variable 'fldContacts', is that what you use to hold the Contact folder?
note: you zip didn't work.
Ok understood.
Going back on our entry ID: 41686229, the variable 'fldContacts', is that what you use to hold the Contact folder?
note: you zip didn't work.
fldContacts is set to the Contacts folder. The notes are used to store the StoreID and EntryID values from the selected folder; they can be used to set a variable to the folder again, without the need for a FolderPicker dialog.
Your computer probably has some security feature that prevents downloading files with code. Here is the entire code module for my UserForm:
Option Explicit
Private Sub cmdOpenContact_Click()
'Created by Helen Feddema 26-Jun-2015
'Last modified by Helen Feddema 1-Jul-2015
On Error GoTo ErrorHandler
Dim varContactsFolderEntryID As Variant
Dim strContactsFolderStoreID As String
Dim fldContacts As Outlook.Folder
Dim fldContactsStoreID As Outlook.Folder
Dim fldContactsEntryID As Outlook.Folder
Dim lst As MSForms.ListBox
Dim strFullName As String
Dim con As Outlook.ContactItem
Dim intCount As Integer
Dim itm As Object
Dim itms As Outlook.Items
Dim nms As Outlook.NameSpace
Dim fldNotes As Outlook.Folder
Dim flds As Outlook.Folders
Dim strFolder As String
Dim strTitle As String
Dim strPrompt As String
Dim blnFound As Boolean
Dim nitm As Outlook.NoteItem
Set lst = Me.lstContacts
strFullName = lst.Value
'Get saved Contacts folder IDs
'The local Notes folder is always used
Set nms = Application.GetNamespace("MAPI")
Set fldNotes = nms.GetDefaultFolder(olFolderNotes)
Set flds = fldNotes.Folders
strFolder = "Contacts Folder Store ID"
strTitle = "Folder not found"
blnFound = FindFolder(flds, strFolder)
If blnFound = False Then
strPrompt = strFolder & " not found; please select Contacts folder"
MsgBox prompt:=strPrompt, _
buttons:=vbExclamation + vbOKOnly, _
Title:=strTitle
fldContacts = SelectContactsFolder
GoTo GetContact
Else
Set fldContactsStoreID = fldNotes.Folders("Contacts Folder Store ID")
Set nitm = fldContactsStoreID.Items(1)
strContactsFolderStoreID = CStr(nitm.Body)
End If
strFolder = "Contacts Folder Entry ID"
blnFound = FindFolder(flds, strFolder)
If blnFound = False Then
strPrompt = strFolder & " not found; please select Contacts folder"
MsgBox prompt:=strPrompt, _
buttons:=vbExclamation + vbOKOnly, _
Title:=strTitle
fldContacts = SelectContactsFolder
GoTo GetContact
Else
Set fldContactsEntryID = fldNotes.Folders("Contacts Folder Entry ID")
Set nitm = fldContactsEntryID.Items(1)
varContactsFolderEntryID = nitm.Body
End If
'Get Contacts folder EntryID and StoreID from notes
'in folders, and set references to the folder
Set fldContacts = nms.GetFolderFromID(varContactsFolderEntryID, _
strContactsFolderStoreID)
GetContact:
Set con = fldContacts.Items(strFullName)
Me.Hide
con.Display
ErrorHandlerExit:
Exit Sub
ErrorHandler:
MsgBox "Error No: " & Err.Number _
& " in cmdOpenContact_Click procedure; " _
& "Description: " & Err.Description
Resume ErrorHandlerExit
End Sub
Private Sub UserForm_Initialize()
'Created by Helen Feddema 26-Jun-2015
'Last modified by Helen Feddema 1-Jul-2015
On Error GoTo ErrorHandler
Dim fldContacts As Outlook.Folder
Dim fldNotes As Outlook.Folder
Dim fldContactsStoreID As Outlook.Folder
Dim fldContactsEntryID As Outlook.Folder
Dim lst As MSForms.ListBox
Dim strFullName As String
Dim intCount As Integer
Dim itm As Object
Dim itms As Outlook.Items
Dim nms As Outlook.NameSpace
Dim nitm As Outlook.NoteItem
Dim strSubFolder As String
Dim strPrompt As String
Dim strTitle As String
Dim strContactsFolderStoreID As String
Dim varContactsFolderEntryID As Variant
Set nms = Application.GetNamespace("MAPI")
Set fldNotes = nms.GetDefaultFolder(olFolderNotes)
'Create various subfolders under local Notes folder, if
'they don't already exist
'strSubFolder = "*"
strSubFolder = "Contacts Folder Store ID"
Set fldContactsStoreID = FindOrAddFolder(fldNotes, strSubFolder)
strSubFolder = "Contacts Folder Entry ID"
Set fldContactsEntryID = FindOrAddFolder(fldNotes, strSubFolder)
'Let user select Contacts folder location
Set fldContacts = SelectContactsFolder
'Save folder's IDs to a note item
Debug.Print "Contacts folder name: " & fldContacts.Name
Debug.Print "Contacts folder store ID: " & fldContacts.StoreID
strContactsFolderStoreID = CStr(fldContacts.StoreID)
varContactsFolderEntryID = CStr(fldContacts.EntryID)
ClearContactsStoreIDNote:
If fldContactsStoreID.Items.Count > 0 Then
fldContactsStoreID.Items(1).Delete
GoTo ClearContactsStoreIDNote
Else
GoTo NewContactsStoreIDNote
End If
NewContactsStoreIDNote:
Set nitm = fldContactsStoreID.Items.Add
nitm.Body = strContactsFolderStoreID
nitm.Close (olSave)
ClearContactsEntryIDNote:
If fldContactsEntryID.Items.Count > 0 Then
fldContactsEntryID.Items(1).Delete
GoTo ClearContactsEntryIDNote
Else
GoTo NewContactsEntryIDNote
End If
NewContactsEntryIDNote:
Set nitm = fldContactsEntryID.Items.Add
nitm.Body = varContactsFolderEntryID
nitm.Close (olSave)
'Fill listbox with small number of FullName values
Set itms = fldContacts.Items
Set lst = Me.lstContacts
intCount = 0
For Each itm In itms
If intCount = 10 Then
GoTo ErrorHandlerExit
Else
strFullName = itm.FullName
Debug.Print "Full name: " & strFullName
If strFullName <> "" Then
lst.AddItem strFullName
intCount = intCount + 1
End If
End If
Next itm
ErrorHandlerExit:
Exit Sub
ErrorHandler:
MsgBox "Error No: " & Err.Number _
& " in frmOpenContact Initialize procedure; " _
& "Description: " & Err.Description
Resume ErrorHandlerExit
End Sub
Private Function FindOrAddFolder(fld As Outlook.Folder, _
strFolder As String) _
As Outlook.Folder
'Created by Helen Feddema 1-10-2002
'Last modified by Helen Feddema 1-Jul-2016
On Error GoTo ErrorHandler
Dim flds As Outlook.Folders
Dim nms As Outlook.NameSpace
Dim blnFound As Boolean
Set nms = Application.GetNamespace("MAPI")
Set flds = fld.Folders
'Check for existence of specified subfolder and exit if not found
blnFound = FindFolder(flds, strFolder)
If blnFound = True Then
Debug.Print strFolder & " already exists"
Set FindOrAddFolder = flds(strFolder)
GoTo ErrorHandlerExit
ElseIf blnFound = False Then
Debug.Print "Creating " & strFolder
Set FindOrAddFolder = flds.Add(strFolder, olFolderNotes)
End If
ErrorHandlerExit:
Exit Function
ErrorHandler:
MsgBox "Error No: " & Err.Number _
& " in FindOrAddFolder procedure; " _
& "Description: " & Err.Description
Resume ErrorHandlerExit
End Function
Private Function FindFolder(fldsParent As Outlook.Folders, _
strShortName As String) As Boolean
'Created by Helen Feddema 1-10-2002
'Last modified by Helen Feddema 1-Jul-2016
On Error GoTo ErrorHandler
Dim fld As Outlook.Folder
For Each fld In fldsParent
If fld.Name = strShortName Then
FindFolder = True
GoTo ErrorHandlerExit
End If
Next fld
ErrorHandlerExit:
Exit Function
ErrorHandler:
MsgBox "Error No: " & Err.Number _
& " in FindFolder procedure; " _
& "Description: " & Err.Description
Resume ErrorHandlerExit
End Function
Private Function SelectContactsFolder() As Outlook.Folder
'Created by Helen Feddema 1-Jul-2015
'Last modified by Helen Feddema 1-Jul-2015
On Error GoTo ErrorHandler
Dim nms As Outlook.NameSpace
Dim fldContacts As Outlook.Folder
Dim strPrompt As String
Dim strTitle As String
'Let user select Contacts folder location
SelectFolder:
Set nms = Application.GetNamespace("MAPI")
Set fldContacts = nms.PickFolder
If fldContacts Is Nothing Then
GoTo ErrorHandlerExit
ElseIf fldContacts.DefaultItemType <> olContactItem Then
strPrompt = "Please select a Contacts folder"
strTitle = "Select folder"
MsgBox prompt:=strPrompt, _
buttons:=vbExclamation + vbOKOnly, _
Title:=strTitle
GoTo SelectFolder
End If
Set SelectContactsFolder = fldContacts
ErrorHandlerExit:
Exit Function
ErrorHandler:
MsgBox "Error No: " & Err.Number _
& " in SelectContactsFolder procedure; " _
& "Description: " & Err.Description
Resume ErrorHandlerExit
End Function
It would be more efficient to declare all (or most) of the variables in the Declarations section at the top of the module, but in this case I declared them within each procedure, to make it easier to copy and paste them into another module.
ASKER
Hi,
Some errors but it must be something in version 2010 the data is currently on; version 2007 works excellently.
So we will proceed to close the question and really thank you for all your help and patience! You have been great with us! As for the problems we are facing, we will review first and if we can't solve it, we'll place a question on EE.
Some errors but it must be something in version 2010 the data is currently on; version 2007 works excellently.
So we will proceed to close the question and really thank you for all your help and patience! You have been great with us! As for the problems we are facing, we will review first and if we can't solve it, we'll place a question on EE.
Open in new window