PC Review
Forums
Newsgroups
Microsoft Outlook
Microsoft Outlook VBA Programming
Cannot convert all contacts, in a public folder, to a new form...
Forums
Newsgroups
Microsoft Outlook
Microsoft Outlook VBA Programming
Cannot convert all contacts, in a public folder, to a new form...
![]() |
Cannot convert all contacts, in a public folder, to a new form... |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
Hi all!
I have a public folder that contains contacts. I was asked to change the contacts from the default form to a slightly different form, more specifically, one that wouldn't show the Certificates tab. I modified the default Contact form and published it as Custom_Contact_View and then I ran a VBA procedure that I found in section 24.1.3 in the book "Microsoft Outlook Programming"(written by Sue Mosher). The procedure ran without a hitch, but when I started opening the contacts, I discovered that some of them had not been converted. I checked and all items in the public folder are of type "Contact", so, what could be the problem? This is the code that I used: '============================================================= ' UpdateMessageClass ' Listing 24.3 '------------------------------------------------------------- ' Purpose : Apply a new form to existing items ' Notes : Assumes g_CDOSession MAPI.Session global variable ' uses reference to Microsoft CDO 1.21 Library (cdo.dll) '============================================================= Sub UpdateMessageClass() Dim objApp As Outlook.Application Dim objNS As Outlook.NameSpace Dim objFolder As Outlook.MAPIFolder Dim objCDOFolder As MAPI.Folder Dim colCDOMessages As MAPI.Messages Dim objCDOMessage As MAPI.Message Dim objFilter As MAPI.MessageFilter Dim strClass As String Dim strFolderClass As String Dim strMsg As String Dim strTitle As String Dim iCntr As Integer On Error Resume Next iCntr = 0 Set objApp = CreateObject("Outlook.Application") Set objNS = objApp.GetNamespace("MAPI") Set objFolder = objNS.PickFolder If Not objFolder Is Nothing Then strMsg = "Change all items in folder to what class?" strTitle = "UpdateMessageClass" strClass = InputBox(strMsg, strTitle) strFolderClass = objFolder.DefaultMessageClass 'MsgBox strFolderClass If InStr(1, strClass, strFolderClass, _ vbTextCompare) Then Call DoCDOLogon Set objCDOFolder = _ g_CDOSession.GetFolder(objFolder.EntryID, _ objFolder.StoreID) Set colCDOMessages = objCDOFolder.Messages Set objFilter = colCDOMessages.Filter objFilter.Type = strFolderClass For Each objCDOMessage In colCDOMessages objCDOMessage.Type = strClass objCDOMessage.Update Next Call DoCDOLogoff strMsg = "Updated items in " & objFolder.Name & " Folder" MsgBox strMsg, , strTitle Else strMsg = "The class you specified is not the normal " & _ "type for this folder. " & _ "No items will be updated." MsgBox strMsg, , strTitle End If End If Set objFolder = Nothing Set objCDOFolder = Nothing Set objCDOMessage = Nothing Set colCDOMessages = Nothing Set objFilter = Nothing Set objNS = Nothing Set objApp = Nothing End Sub |
|
|
|
#2 |
|
Guest
Posts: n/a
|
I would suggest that you step through the code in the VBA debugger so you
can follow the logic and discover what's not working as expected. Remarking out the On Error Resume Next line would also be a good troubleshooting technique -- so you can be notified of any errors. -- Sue Mosher, Outlook MVP Author of Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx "Valentin" <valentin_ionita@yahoo.com> wrote in message news:f1869211.0404300837.415608a5@posting.google.com... > Hi all! > > I have a public folder that contains contacts. I was asked to change > the contacts from the default form to a slightly different form, more > specifically, one that wouldn't show the Certificates tab. > I modified the default Contact form and published it as > Custom_Contact_View and then I ran a VBA procedure that I found in > section 24.1.3 in the book "Microsoft Outlook Programming"(written by > Sue Mosher). The procedure ran without a hitch, but when I started > opening the contacts, I discovered that some of them had not been > converted. I checked and all items in the public folder are of type > "Contact", so, what could be the problem? > > This is the code that I used: > '============================================================= > ' UpdateMessageClass > ' Listing 24.3 > '------------------------------------------------------------- > ' Purpose : Apply a new form to existing items > ' Notes : Assumes g_CDOSession MAPI.Session global variable > ' uses reference to Microsoft CDO 1.21 Library (cdo.dll) > '============================================================= > Sub UpdateMessageClass() > Dim objApp As Outlook.Application > Dim objNS As Outlook.NameSpace > Dim objFolder As Outlook.MAPIFolder > Dim objCDOFolder As MAPI.Folder > Dim colCDOMessages As MAPI.Messages > Dim objCDOMessage As MAPI.Message > Dim objFilter As MAPI.MessageFilter > Dim strClass As String > Dim strFolderClass As String > Dim strMsg As String > Dim strTitle As String > > Dim iCntr As Integer > > On Error Resume Next > > iCntr = 0 > Set objApp = CreateObject("Outlook.Application") > Set objNS = objApp.GetNamespace("MAPI") > Set objFolder = objNS.PickFolder > If Not objFolder Is Nothing Then > strMsg = "Change all items in folder to what class?" > strTitle = "UpdateMessageClass" > strClass = InputBox(strMsg, strTitle) > strFolderClass = objFolder.DefaultMessageClass > 'MsgBox strFolderClass > If InStr(1, strClass, strFolderClass, _ > vbTextCompare) Then > Call DoCDOLogon > Set objCDOFolder = _ > g_CDOSession.GetFolder(objFolder.EntryID, _ > objFolder.StoreID) > Set colCDOMessages = objCDOFolder.Messages > Set objFilter = colCDOMessages.Filter > objFilter.Type = strFolderClass > For Each objCDOMessage In colCDOMessages > objCDOMessage.Type = strClass > objCDOMessage.Update > Next > Call DoCDOLogoff > strMsg = "Updated items in " & objFolder.Name & " Folder" > MsgBox strMsg, , strTitle > Else > strMsg = "The class you specified is not the normal " & _ > "type for this folder. " & _ > "No items will be updated." > MsgBox strMsg, , strTitle > End If > End If > > Set objFolder = Nothing > Set objCDOFolder = Nothing > Set objCDOMessage = Nothing > Set colCDOMessages = Nothing > Set objFilter = Nothing > Set objNS = Nothing > Set objApp = Nothing > End Sub |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

