Rebuild Contacts Links

S

Sue Mosher [MVP-Outlook]

What statement gives you that error?

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


chunnel said:
I have tried what you mentioned but am still getting "Sub or Function not
defined". I hate to cut and paste the whole thing, but can you see an error
with what I've written?

Sub ReconnectLinks()
Dim objApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim objFolder As Outlook.MAPIFolder
Dim colItems As Outlook.Items
Dim objItem As Object
Dim colLinks As Outlook.Links
Dim objLink As Outlook.Link
Dim colContacts As Outlook.Items
Dim objContact As Outlook.ContactItem
Dim strFind As String
Dim intCount As Integer
Dim I As Integer
Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")
Set objFolder = objNS.PickFolder
If TypeName(objFolder) <> "Nothing" Then
Set colContacts = _
objNS.GetDefaultFolder(olFolderContacts).Items
Set colItems = objFolder.Items
For Each objItem In colItems
Set colLinks = objItem.Links
intCount = colLinks.Count
If intCount > 0 Then
For I = intCount To 1 Step -1
Set objLink = colLinks.Item(I)
On Error Resume Next
If objLink.Item Is Nothing Then
strFind = "[FullName] = " & Quote(objLink.Name)
Set objContact = colContacts.Find(strFind)
If Not objContact Is Nothing Then
colLinks.Remove I
colLinks.Add objContact
End If
End If
Next
If Not objItem.Saved Then
objItem.Save
End If
End If
Next
End If

Set colContacts = Nothing
Set objContacts = Nothing
Set objLink = Nothing
Set colLinks = Nothing
Set objItem = Nothing
Set objItems = Nothing
Set objFolder = Nothing
Set objNS = Nothing
Set objApp = Nothing
End Sub
Private Function Quote(varInput)
Quote = Chr(34) & varInput & Chr(34)
End Function







Sue Mosher said:
The underscore is a continuation character. If you put the entire statement on one line, you must take the underscore out. If you leave it in, the quotation mark needs to be after the equals sign.

chunnel said:
I tried the ReconnectLinks () from Listing 20.2 and I keep getting an error
at the line which is as follows;
If objLink.item Is Nothing Then
strFind = "[FullName] = _
" & Quote(objLink.Name)

If I type it as written then I get an compile error for unexpected end of
statement because I hit return after the "_". If it keep the 3rd line as
part of the 2nd line so that it looks as follows;
strFind = "[FullName] = _" & Quote(objLink.Name)
then I get an error when running it that Sub or Function is not defined and
it focuses on this line.
 
C

chunnel

I get the error when I run the macro through the Tools menu in Outlook. When
I enter the VB Editor and run it from there and choose the Contacts section
when the window pops up, it gives me an hourglass for a few minutes so it
appears to be doing something. However, none of the links appear to have
been fixed because of it. So I don't know if there is a problem or not or if
the program can't fix it.

When I do get the error it doesn't highlight anything to tell me what the
problem is, so I can't tell you. And I get no error when I try to debug.

Bryan

Sue Mosher said:
What statement gives you that error?

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


chunnel said:
I have tried what you mentioned but am still getting "Sub or Function not
defined". I hate to cut and paste the whole thing, but can you see an error
with what I've written?

Sub ReconnectLinks()
Dim objApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim objFolder As Outlook.MAPIFolder
Dim colItems As Outlook.Items
Dim objItem As Object
Dim colLinks As Outlook.Links
Dim objLink As Outlook.Link
Dim colContacts As Outlook.Items
Dim objContact As Outlook.ContactItem
Dim strFind As String
Dim intCount As Integer
Dim I As Integer
Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")
Set objFolder = objNS.PickFolder
If TypeName(objFolder) <> "Nothing" Then
Set colContacts = _
objNS.GetDefaultFolder(olFolderContacts).Items
Set colItems = objFolder.Items
For Each objItem In colItems
Set colLinks = objItem.Links
intCount = colLinks.Count
If intCount > 0 Then
For I = intCount To 1 Step -1
Set objLink = colLinks.Item(I)
On Error Resume Next
If objLink.Item Is Nothing Then
strFind = "[FullName] = " & Quote(objLink.Name)
Set objContact = colContacts.Find(strFind)
If Not objContact Is Nothing Then
colLinks.Remove I
colLinks.Add objContact
End If
End If
Next
If Not objItem.Saved Then
objItem.Save
End If
End If
Next
End If

Set colContacts = Nothing
Set objContacts = Nothing
Set objLink = Nothing
Set colLinks = Nothing
Set objItem = Nothing
Set objItems = Nothing
Set objFolder = Nothing
Set objNS = Nothing
Set objApp = Nothing
End Sub
Private Function Quote(varInput)
Quote = Chr(34) & varInput & Chr(34)
End Function







Sue Mosher said:
The underscore is a continuation character. If you put the entire statement on one line, you must take the underscore out. If you leave it in, the quotation mark needs to be after the equals sign.

I tried the ReconnectLinks () from Listing 20.2 and I keep getting an error
at the line which is as follows;
If objLink.item Is Nothing Then
strFind = "[FullName] = _
" & Quote(objLink.Name)

If I type it as written then I get an compile error for unexpected end of
statement because I hit return after the "_". If it keep the 3rd line as
part of the 2nd line so that it looks as follows;
strFind = "[FullName] = _" & Quote(objLink.Name)
then I get an error when running it that Sub or Function is not defined and
it focuses on this line.
 
S

Sue Mosher [MVP-Outlook]

I'd suggest that you step through the code using F8 so that you see every statement execute. That ought to give you a better idea of what's going on.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


chunnel said:
I get the error when I run the macro through the Tools menu in Outlook. When
I enter the VB Editor and run it from there and choose the Contacts section
when the window pops up, it gives me an hourglass for a few minutes so it
appears to be doing something. However, none of the links appear to have
been fixed because of it. So I don't know if there is a problem or not or if
the program can't fix it.

When I do get the error it doesn't highlight anything to tell me what the
problem is, so I can't tell you. And I get no error when I try to debug.

Bryan

Sue Mosher said:
What statement gives you that error?

chunnel said:
I have tried what you mentioned but am still getting "Sub or Function not
defined". I hate to cut and paste the whole thing, but can you see an error
with what I've written?

Sub ReconnectLinks()
Dim objApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim objFolder As Outlook.MAPIFolder
Dim colItems As Outlook.Items
Dim objItem As Object
Dim colLinks As Outlook.Links
Dim objLink As Outlook.Link
Dim colContacts As Outlook.Items
Dim objContact As Outlook.ContactItem
Dim strFind As String
Dim intCount As Integer
Dim I As Integer
Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")
Set objFolder = objNS.PickFolder
If TypeName(objFolder) <> "Nothing" Then
Set colContacts = _
objNS.GetDefaultFolder(olFolderContacts).Items
Set colItems = objFolder.Items
For Each objItem In colItems
Set colLinks = objItem.Links
intCount = colLinks.Count
If intCount > 0 Then
For I = intCount To 1 Step -1
Set objLink = colLinks.Item(I)
On Error Resume Next
If objLink.Item Is Nothing Then
strFind = "[FullName] = " & Quote(objLink.Name)
Set objContact = colContacts.Find(strFind)
If Not objContact Is Nothing Then
colLinks.Remove I
colLinks.Add objContact
End If
End If
Next
If Not objItem.Saved Then
objItem.Save
End If
End If
Next
End If

Set colContacts = Nothing
Set objContacts = Nothing
Set objLink = Nothing
Set colLinks = Nothing
Set objItem = Nothing
Set objItems = Nothing
Set objFolder = Nothing
Set objNS = Nothing
Set objApp = Nothing
End Sub
Private Function Quote(varInput)
Quote = Chr(34) & varInput & Chr(34)
End Function

:

The underscore is a continuation character. If you put the entire statement on one line, you must take the underscore out. If you leave it in, the quotation mark needs to be after the equals sign.
I tried the ReconnectLinks () from Listing 20.2 and I keep getting an error
at the line which is as follows;
If objLink.item Is Nothing Then
strFind = "[FullName] = _
" & Quote(objLink.Name)

If I type it as written then I get an compile error for unexpected end of
statement because I hit return after the "_". If it keep the 3rd line as
part of the 2nd line so that it looks as follows;
strFind = "[FullName] = _" & Quote(objLink.Name)
then I get an error when running it that Sub or Function is not defined and
it focuses on this line.
 
C

chunnel

I did run F8 and received no errors. But all of my links have been
destroyed. I have to retype any link that I want to access. The problem is
that I have probably over 1,000 linked contacts.

Sue Mosher said:
I'd suggest that you step through the code using F8 so that you see every statement execute. That ought to give you a better idea of what's going on.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


chunnel said:
I get the error when I run the macro through the Tools menu in Outlook. When
I enter the VB Editor and run it from there and choose the Contacts section
when the window pops up, it gives me an hourglass for a few minutes so it
appears to be doing something. However, none of the links appear to have
been fixed because of it. So I don't know if there is a problem or not or if
the program can't fix it.

When I do get the error it doesn't highlight anything to tell me what the
problem is, so I can't tell you. And I get no error when I try to debug.

Bryan

Sue Mosher said:
What statement gives you that error?

I have tried what you mentioned but am still getting "Sub or Function not
defined". I hate to cut and paste the whole thing, but can you see an error
with what I've written?

Sub ReconnectLinks()
Dim objApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim objFolder As Outlook.MAPIFolder
Dim colItems As Outlook.Items
Dim objItem As Object
Dim colLinks As Outlook.Links
Dim objLink As Outlook.Link
Dim colContacts As Outlook.Items
Dim objContact As Outlook.ContactItem
Dim strFind As String
Dim intCount As Integer
Dim I As Integer
Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")
Set objFolder = objNS.PickFolder
If TypeName(objFolder) <> "Nothing" Then
Set colContacts = _
objNS.GetDefaultFolder(olFolderContacts).Items
Set colItems = objFolder.Items
For Each objItem In colItems
Set colLinks = objItem.Links
intCount = colLinks.Count
If intCount > 0 Then
For I = intCount To 1 Step -1
Set objLink = colLinks.Item(I)
On Error Resume Next
If objLink.Item Is Nothing Then
strFind = "[FullName] = " & Quote(objLink.Name)
Set objContact = colContacts.Find(strFind)
If Not objContact Is Nothing Then
colLinks.Remove I
colLinks.Add objContact
End If
End If
Next
If Not objItem.Saved Then
objItem.Save
End If
End If
Next
End If

Set colContacts = Nothing
Set objContacts = Nothing
Set objLink = Nothing
Set colLinks = Nothing
Set objItem = Nothing
Set objItems = Nothing
Set objFolder = Nothing
Set objNS = Nothing
Set objApp = Nothing
End Sub
Private Function Quote(varInput)
Quote = Chr(34) & varInput & Chr(34)
End Function

:

The underscore is a continuation character. If you put the entire statement on one line, you must take the underscore out. If you leave it in, the quotation mark needs to be after the equals sign.


I tried the ReconnectLinks () from Listing 20.2 and I keep getting an error
at the line which is as follows;
If objLink.item Is Nothing Then
strFind = "[FullName] = _
" & Quote(objLink.Name)

If I type it as written then I get an compile error for unexpected end of
statement because I hit return after the "_". If it keep the 3rd line as
part of the 2nd line so that it looks as follows;
strFind = "[FullName] = _" & Quote(objLink.Name)
then I get an error when running it that Sub or Function is not defined and
it focuses on this line.
 
S

Sue Mosher [MVP-Outlook]

You're not looking for errors but to see whether the code actually found a matching contact, which is a prerequisite to fixing the link. Remember, we can't look over your shoulder to see what's going on with the data itself.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


chunnel said:
I did run F8 and received no errors. But all of my links have been
destroyed. I have to retype any link that I want to access. The problem is
that I have probably over 1,000 linked contacts.

Sue Mosher said:
I'd suggest that you step through the code using F8 so that you see every statement execute. That ought to give you a better idea of what's going on.

chunnel said:
I get the error when I run the macro through the Tools menu in Outlook. When
I enter the VB Editor and run it from there and choose the Contacts section
when the window pops up, it gives me an hourglass for a few minutes so it
appears to be doing something. However, none of the links appear to have
been fixed because of it. So I don't know if there is a problem or not or if
the program can't fix it.

When I do get the error it doesn't highlight anything to tell me what the
problem is, so I can't tell you. And I get no error when I try to debug.

Bryan

:

What statement gives you that error?

I have tried what you mentioned but am still getting "Sub or Function not
defined". I hate to cut and paste the whole thing, but can you see an error
with what I've written?

Sub ReconnectLinks()
Dim objApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim objFolder As Outlook.MAPIFolder
Dim colItems As Outlook.Items
Dim objItem As Object
Dim colLinks As Outlook.Links
Dim objLink As Outlook.Link
Dim colContacts As Outlook.Items
Dim objContact As Outlook.ContactItem
Dim strFind As String
Dim intCount As Integer
Dim I As Integer
Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")
Set objFolder = objNS.PickFolder
If TypeName(objFolder) <> "Nothing" Then
Set colContacts = _
objNS.GetDefaultFolder(olFolderContacts).Items
Set colItems = objFolder.Items
For Each objItem In colItems
Set colLinks = objItem.Links
intCount = colLinks.Count
If intCount > 0 Then
For I = intCount To 1 Step -1
Set objLink = colLinks.Item(I)
On Error Resume Next
If objLink.Item Is Nothing Then
strFind = "[FullName] = " & Quote(objLink.Name)
Set objContact = colContacts.Find(strFind)
If Not objContact Is Nothing Then
colLinks.Remove I
colLinks.Add objContact
End If
End If
Next
If Not objItem.Saved Then
objItem.Save
End If
End If
Next
End If

Set colContacts = Nothing
Set objContacts = Nothing
Set objLink = Nothing
Set colLinks = Nothing
Set objItem = Nothing
Set objItems = Nothing
Set objFolder = Nothing
Set objNS = Nothing
Set objApp = Nothing
End Sub
Private Function Quote(varInput)
Quote = Chr(34) & varInput & Chr(34)
End Function
:

The underscore is a continuation character. If you put the entire statement on one line, you must take the underscore out. If you leave it in, the quotation mark needs to be after the equals sign.


I tried the ReconnectLinks () from Listing 20.2 and I keep getting an error
at the line which is as follows;
If objLink.item Is Nothing Then
strFind = "[FullName] = _
" & Quote(objLink.Name)

If I type it as written then I get an compile error for unexpected end of
statement because I hit return after the "_". If it keep the 3rd line as
part of the 2nd line so that it looks as follows;
strFind = "[FullName] = _" & Quote(objLink.Name)
then I get an error when running it that Sub or Function is not defined and
it focuses on this line.
 
M

Michael Ray Brown

I've unfortunately had the same catastrophe befall me. After upgrading to
Outlook 2007 and running the recent patch, all the links to my Contacts from
my Journal items, Task items, and Calendar items suddenly went dead.

I copied and pasted the VBA script into Outlook, and ran the macro, but
nothing has changed. Whenever I double click on a name in a Journal item's
"Contacts" field, for example, I still get an error message:

"Cannot perform the requested operation. The command selected is not valid
for this recipient. An internal support function returned an error."

--
Michael

The underscore is a continuation character. If you put the entire statement
on one line, you must take the underscore out. If you leave it in, the
quotation mark needs to be after the equals sign.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
S

Sue Mosher [MVP-Outlook]

What happens if you step through the code in the debugger? Can you see it execute the statements where it adds a link, removes the old link, and saves the item?
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


Michael Ray Brown said:
I've unfortunately had the same catastrophe befall me. After upgrading to
Outlook 2007 and running the recent patch, all the links to my Contacts from
my Journal items, Task items, and Calendar items suddenly went dead.

I copied and pasted the VBA script into Outlook, and ran the macro, but
nothing has changed. Whenever I double click on a name in a Journal item's
"Contacts" field, for example, I still get an error message:

"Cannot perform the requested operation. The command selected is not valid
for this recipient. An internal support function returned an error."

--
Michael

The underscore is a continuation character. If you put the entire statement
on one line, you must take the underscore out. If you leave it in, the
quotation mark needs to be after the equals sign.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


chunnel said:
I tried the ReconnectLinks () from Listing 20.2 and I keep getting an error
at the line which is as follows;
If objLink.item Is Nothing Then
strFind = "[FullName] = _
" & Quote(objLink.Name)

If I type it as written then I get an compile error for unexpected end of
statement because I hit return after the "_". If it keep the 3rd line as
part of the 2nd line so that it looks as follows;
strFind = "[FullName] = _" & Quote(objLink.Name)
then I get an error when running it that Sub or Function is not defined
and
it focuses on this line.
 
M

Michael Ray Brown

I'm a bit out of my depth here. I'm a writer, not a programmer. However,
when I press "F8" to step through the script, it gets to the line...

If intCount > 0 Then

.... and then the highlighting jumps to...

End If

It does this over and over again. I never see any link being added or
removed.

--
Michael

What happens if you step through the code in the debugger? Can you see it
execute the statements where it adds a link, removes the old link, and saves
the item?
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


Michael Ray Brown said:
I've unfortunately had the same catastrophe befall me. After upgrading to
Outlook 2007 and running the recent patch, all the links to my Contacts
from
my Journal items, Task items, and Calendar items suddenly went dead.

I copied and pasted the VBA script into Outlook, and ran the macro, but
nothing has changed. Whenever I double click on a name in a Journal
item's
"Contacts" field, for example, I still get an error message:

"Cannot perform the requested operation. The command selected is not valid
for this recipient. An internal support function returned an error."

--
Michael

The underscore is a continuation character. If you put the entire
statement
on one line, you must take the underscore out. If you leave it in, the
quotation mark needs to be after the equals sign.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


chunnel said:
I tried the ReconnectLinks () from Listing 20.2 and I keep getting an
error
at the line which is as follows;
If objLink.item Is Nothing Then
strFind = "[FullName] = _
" & Quote(objLink.Name)

If I type it as written then I get an compile error for unexpected end of
statement because I hit return after the "_". If it keep the 3rd line as
part of the 2nd line so that it looks as follows;
strFind = "[FullName] = _" & Quote(objLink.Name)
then I get an error when running it that Sub or Function is not defined
and
it focuses on this line.
 
S

Sue Mosher [MVP-Outlook]

That means that intCount equals zero, that the item being worked on has no contact links.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


Michael Ray Brown said:
I'm a bit out of my depth here. I'm a writer, not a programmer. However,
when I press "F8" to step through the script, it gets to the line...

If intCount > 0 Then

... and then the highlighting jumps to...

End If

It does this over and over again. I never see any link being added or
removed.

--
Michael

What happens if you step through the code in the debugger? Can you see it
execute the statements where it adds a link, removes the old link, and saves
the item?

Michael Ray Brown said:
I've unfortunately had the same catastrophe befall me. After upgrading to
Outlook 2007 and running the recent patch, all the links to my Contacts
from
my Journal items, Task items, and Calendar items suddenly went dead.

I copied and pasted the VBA script into Outlook, and ran the macro, but
nothing has changed. Whenever I double click on a name in a Journal
item's
"Contacts" field, for example, I still get an error message:

"Cannot perform the requested operation. The command selected is not valid
for this recipient. An internal support function returned an error."

--
Michael

The underscore is a continuation character. If you put the entire
statement
on one line, you must take the underscore out. If you leave it in, the
quotation mark needs to be after the equals sign.

chunnel said:
I tried the ReconnectLinks () from Listing 20.2 and I keep getting an
error
at the line which is as follows;
If objLink.item Is Nothing Then
strFind = "[FullName] = _
" & Quote(objLink.Name)

If I type it as written then I get an compile error for unexpected end of
statement because I hit return after the "_". If it keep the 3rd line as
part of the 2nd line so that it looks as follows;
strFind = "[FullName] = _" & Quote(objLink.Name)
then I get an error when running it that Sub or Function is not defined
and
it focuses on this line.
 
M

Michael Ray Brown

Well, it must be missing something because all my Journal items, Calendar
items, and Task items have links to at least one Contact.

Just so I'm clear on how to run the macro: When it asks me to choose a
folder, I select the folder that contains the items which need to be
re-linked to a contact record. If I decipher the macro correctly, it
defaults to the Contacts folder if no folder is selected, meaning that it
looks for links to other contacts in each contact record.

--
Michael

That means that intCount equals zero, that the item being worked on has no
contact links.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


Michael Ray Brown said:
I'm a bit out of my depth here. I'm a writer, not a programmer. However,
when I press "F8" to step through the script, it gets to the line...

If intCount > 0 Then

... and then the highlighting jumps to...

End If

It does this over and over again. I never see any link being added or
removed.

--
Michael

What happens if you step through the code in the debugger? Can you see it
execute the statements where it adds a link, removes the old link, and
saves
the item?

Michael Ray Brown said:
I've unfortunately had the same catastrophe befall me. After upgrading
to
Outlook 2007 and running the recent patch, all the links to my Contacts
from
my Journal items, Task items, and Calendar items suddenly went dead.

I copied and pasted the VBA script into Outlook, and ran the macro, but
nothing has changed. Whenever I double click on a name in a Journal
item's
"Contacts" field, for example, I still get an error message:

"Cannot perform the requested operation. The command selected is not
valid
for this recipient. An internal support function returned an error."

--
Michael

The underscore is a continuation character. If you put the entire
statement
on one line, you must take the underscore out. If you leave it in, the
quotation mark needs to be after the equals sign.

chunnel said:
I tried the ReconnectLinks () from Listing 20.2 and I keep getting an
error
at the line which is as follows;
If objLink.item Is Nothing Then
strFind = "[FullName] = _
" & Quote(objLink.Name)

If I type it as written then I get an compile error for unexpected end
of
statement because I hit return after the "_". If it keep the 3rd line
as
part of the 2nd line so that it looks as follows;
strFind = "[FullName] = _" & Quote(objLink.Name)
then I get an error when running it that Sub or Function is not defined
and
it focuses on this line.
 
S

Sue Mosher [MVP-Outlook]

Well, it must be missing something because all my Journal items, Calendar
items, and Task items have links to at least one Contact.

All I can say is that intCount is derived from the Count property of the Links collection on the item being processed. You can add a Debug.Print objItem.Subject, objItem.Links.Count statement inside the For Each loop to get a list of the items and their link counts. The list will show in the immediate window.
Just so I'm clear on how to run the macro: When it asks me to choose a
folder, I select the folder that contains the items which need to be
re-linked to a contact record.

Yes, that's correct.
If I decipher the macro correctly, it
defaults to the Contacts folder if no folder is selected, meaning that it
looks for links to other contacts in each contact record.

No, if no folder is selected, no items will be processed at all.

The code looks for matching contacts only in the user's default Contacts folder, not in any other contacts folders that might be present.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers

--
Michael

That means that intCount equals zero, that the item being worked on has no
contact links.

Michael Ray Brown said:
I'm a bit out of my depth here. I'm a writer, not a programmer. However,
when I press "F8" to step through the script, it gets to the line...

If intCount > 0 Then

... and then the highlighting jumps to...

End If

It does this over and over again. I never see any link being added or
removed.

--
Michael

What happens if you step through the code in the debugger? Can you see it
execute the statements where it adds a link, removes the old link, and
saves
the item?

Michael Ray Brown said:
I've unfortunately had the same catastrophe befall me. After upgrading
to
Outlook 2007 and running the recent patch, all the links to my Contacts
from
my Journal items, Task items, and Calendar items suddenly went dead.

I copied and pasted the VBA script into Outlook, and ran the macro, but
nothing has changed. Whenever I double click on a name in a Journal
item's
"Contacts" field, for example, I still get an error message:

"Cannot perform the requested operation. The command selected is not
valid
for this recipient. An internal support function returned an error."

--
Michael

The underscore is a continuation character. If you put the entire
statement
on one line, you must take the underscore out. If you leave it in, the
quotation mark needs to be after the equals sign.

I tried the ReconnectLinks () from Listing 20.2 and I keep getting an
error
at the line which is as follows;
If objLink.item Is Nothing Then
strFind = "[FullName] = _
" & Quote(objLink.Name)

If I type it as written then I get an compile error for unexpected end
of
statement because I hit return after the "_". If it keep the 3rd line
as
part of the 2nd line so that it looks as follows;
strFind = "[FullName] = _" & Quote(objLink.Name)
then I get an error when running it that Sub or Function is not defined
and
it focuses on this line.
 
M

Michael Ray Brown

I took your advice, and added the statement to list the items and their link
counts. When I run the macro, though, nothing shows up. To make sure I've
got it right, I'm pasting the entire script below. Please forgive the long
post.

--
Michael

-------------------------------------------

Sub FixContactLinks()
Dim objNS As NameSpace
Dim objFolder As MAPIFolder
Dim colItems As Items
Dim objItem As Object
Dim colLinks As Links
Dim objLink As Link
Dim colContacts As Items
Dim objContact As ContactItem
Dim strFind As String
Dim intCount As Integer
On Error Resume Next
Set objNS = Application.Session
Set objFolder = objNS.PickFolder
If Not objFolder Is Nothing Then
Set colContacts = _
objNS.GetDefaultFolder(olFolderContacts).Items
Set colItems = objFolder.Items
For Each objItem In colItems
Debug.Print objItem.Subject, objItem.Links.Count
If objItem.Class = olContact Then
Set colLinks = objItem.Links
intCount = colLinks.Count
If intCount > 0 Then
For i = intCount To 1 Step -1
Set objLink = colLinks.Item(i)
If objLink.Item Is Nothing Then
strFind = "[FullName] = " & Quote(objLink.Name)
Set objContact = colContacts.Find(strFind)
If Not objContact Is Nothing Then
' remove the old link
colLinks.Remove i
' add the replacement link
colLinks.Add objContact
End If
End If
Next
objItem.Save
End If
End If
Next
End If
Set objLink = Nothing
Set colLinks = Nothing
Set objItem = Nothing
Set objItems = Nothing
Set objFolder = Nothing
Set objNS = Nothing
Set objContact = Nothing
Set objApp = Nothing
End Sub
Function Quote(val) As String
Quote = Chr(34) & CStr(val) & Chr(34)
End Function

---------------------------------------------
Sue Mosher said:
Well, it must be missing something because all my Journal items, Calendar
items, and Task items have links to at least one Contact.

All I can say is that intCount is derived from the Count property of the
Links collection on the item being processed. You can add a Debug.Print
objItem.Subject, objItem.Links.Count statement inside the For Each loop to
get a list of the items and their link counts. The list will show in the
immediate window.
Just so I'm clear on how to run the macro: When it asks me to choose a
folder, I select the folder that contains the items which need to be
re-linked to a contact record.

Yes, that's correct.
If I decipher the macro correctly, it
defaults to the Contacts folder if no folder is selected, meaning that it
looks for links to other contacts in each contact record.

No, if no folder is selected, no items will be processed at all.

The code looks for matching contacts only in the user's default Contacts
folder, not in any other contacts folders that might be present.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers

--
Michael

That means that intCount equals zero, that the item being worked on has no
contact links.

Michael Ray Brown said:
I'm a bit out of my depth here. I'm a writer, not a programmer.
However,
when I press "F8" to step through the script, it gets to the line...

If intCount > 0 Then

... and then the highlighting jumps to...

End If

It does this over and over again. I never see any link being added or
removed.

--
Michael

What happens if you step through the code in the debugger? Can you see it
execute the statements where it adds a link, removes the old link, and
saves
the item?

Michael Ray Brown said:
I've unfortunately had the same catastrophe befall me. After upgrading
to
Outlook 2007 and running the recent patch, all the links to my Contacts
from
my Journal items, Task items, and Calendar items suddenly went dead.

I copied and pasted the VBA script into Outlook, and ran the macro, but
nothing has changed. Whenever I double click on a name in a Journal
item's
"Contacts" field, for example, I still get an error message:

"Cannot perform the requested operation. The command selected is not
valid
for this recipient. An internal support function returned an error."

--
Michael

The underscore is a continuation character. If you put the entire
statement
on one line, you must take the underscore out. If you leave it in, the
quotation mark needs to be after the equals sign.

I tried the ReconnectLinks () from Listing 20.2 and I keep getting an
error
at the line which is as follows;
If objLink.item Is Nothing Then
strFind = "[FullName] = _
" & Quote(objLink.Name)

If I type it as written then I get an compile error for unexpected end
of
statement because I hit return after the "_". If it keep the 3rd line
as
part of the 2nd line so that it looks as follows;
strFind = "[FullName] = _" & Quote(objLink.Name)
then I get an error when running it that Sub or Function is not defined
and
it focuses on this line.
 
S

Sue Mosher [MVP-Outlook]

I see one problem. This particular code will only update contacts because of the first and last statements in this snippet:

If objItem.Class = olContact Then ' <<<< don't need this
Set colLinks = objItem.Links
intCount = colLinks.Count
If intCount > 0 Then
For i = intCount To 1 Step -1
Set objLink = colLinks.Item(i)
If objLink.Item Is Nothing Then
strFind = "[FullName] = " & Quote(objLink.Name)
Set objContact = colContacts.Find(strFind)
If Not objContact Is Nothing Then
' remove the old link
colLinks.Remove i
' add the replacement link
colLinks.Add objContact
End If
End If
Next
objItem.Save
End If
End If ' <<<< don't need this

Try deleting those two statements.

Also is the code actually executing the Debug.Print statement? Did you display the Immediate window?

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


Michael Ray Brown said:
I took your advice, and added the statement to list the items and their link
counts. When I run the macro, though, nothing shows up. To make sure I've
got it right, I'm pasting the entire script below. Please forgive the long
post.

--
Michael

-------------------------------------------

Sub FixContactLinks()
Dim objNS As NameSpace
Dim objFolder As MAPIFolder
Dim colItems As Items
Dim objItem As Object
Dim colLinks As Links
Dim objLink As Link
Dim colContacts As Items
Dim objContact As ContactItem
Dim strFind As String
Dim intCount As Integer
On Error Resume Next
Set objNS = Application.Session
Set objFolder = objNS.PickFolder
If Not objFolder Is Nothing Then
Set colContacts = _
objNS.GetDefaultFolder(olFolderContacts).Items
Set colItems = objFolder.Items
For Each objItem In colItems
Debug.Print objItem.Subject, objItem.Links.Count
If objItem.Class = olContact Then
Set colLinks = objItem.Links
intCount = colLinks.Count
If intCount > 0 Then
For i = intCount To 1 Step -1
Set objLink = colLinks.Item(i)
If objLink.Item Is Nothing Then
strFind = "[FullName] = " & Quote(objLink.Name)
Set objContact = colContacts.Find(strFind)
If Not objContact Is Nothing Then
' remove the old link
colLinks.Remove i
' add the replacement link
colLinks.Add objContact
End If
End If
Next
objItem.Save
End If
End If
Next
End If
Set objLink = Nothing
Set colLinks = Nothing
Set objItem = Nothing
Set objItems = Nothing
Set objFolder = Nothing
Set objNS = Nothing
Set objContact = Nothing
Set objApp = Nothing
End Sub
Function Quote(val) As String
Quote = Chr(34) & CStr(val) & Chr(34)
End Function

---------------------------------------------
Sue Mosher said:
Well, it must be missing something because all my Journal items, Calendar
items, and Task items have links to at least one Contact.

All I can say is that intCount is derived from the Count property of the
Links collection on the item being processed. You can add a Debug.Print
objItem.Subject, objItem.Links.Count statement inside the For Each loop to
get a list of the items and their link counts. The list will show in the
immediate window.
Just so I'm clear on how to run the macro: When it asks me to choose a
folder, I select the folder that contains the items which need to be
re-linked to a contact record.

Yes, that's correct.
If I decipher the macro correctly, it
defaults to the Contacts folder if no folder is selected, meaning that it
looks for links to other contacts in each contact record.

No, if no folder is selected, no items will be processed at all.

The code looks for matching contacts only in the user's default Contacts
folder, not in any other contacts folders that might be present.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers

--
Michael

That means that intCount equals zero, that the item being worked on has no
contact links.

Michael Ray Brown said:
I'm a bit out of my depth here. I'm a writer, not a programmer.
However,
when I press "F8" to step through the script, it gets to the line...

If intCount > 0 Then

... and then the highlighting jumps to...

End If

It does this over and over again. I never see any link being added or
removed.

--
Michael

What happens if you step through the code in the debugger? Can you see it
execute the statements where it adds a link, removes the old link, and
saves
the item?

I've unfortunately had the same catastrophe befall me. After upgrading
to
Outlook 2007 and running the recent patch, all the links to my Contacts
from
my Journal items, Task items, and Calendar items suddenly went dead.

I copied and pasted the VBA script into Outlook, and ran the macro, but
nothing has changed. Whenever I double click on a name in a Journal
item's
"Contacts" field, for example, I still get an error message:

"Cannot perform the requested operation. The command selected is not
valid
for this recipient. An internal support function returned an error."

--
Michael

The underscore is a continuation character. If you put the entire
statement
on one line, you must take the underscore out. If you leave it in, the
quotation mark needs to be after the equals sign.
I tried the ReconnectLinks () from Listing 20.2 and I keep getting an
error
at the line which is as follows;
If objLink.item Is Nothing Then
strFind = "[FullName] = _
" & Quote(objLink.Name)

If I type it as written then I get an compile error for unexpected end
of
statement because I hit return after the "_". If it keep the 3rd line
as
part of the 2nd line so that it looks as follows;
strFind = "[FullName] = _" & Quote(objLink.Name)
then I get an error when running it that Sub or Function is not defined
and
it focuses on this line.
 
M

Michael Ray Brown

That did the trick! I ran it on my Journal items and Task items, and all
the links now work. Wow! Thank you!

Unfortunately, I still have problems with Calendar items. For some strange
reason, when I run the macro on the Calendar folder, it doesn't fix the
links. However, when I step through the macro, it seems to work. I see an
appointment item come up in the Immediate window, showing the number of
links, and when I go to that appointment and double-click on the link, it
works.

I'd step through the whole calendar, item-by-item, but that's a lot of "F8"
keystrokes. Can you see why the macro doesn't work on Calendar items?

--
Michael

I see one problem. This particular code will only update contacts because of
the first and last statements in this snippet:

If objItem.Class = olContact Then ' <<<< don't need this
Set colLinks = objItem.Links
intCount = colLinks.Count
If intCount > 0 Then
For i = intCount To 1 Step -1
Set objLink = colLinks.Item(i)
If objLink.Item Is Nothing Then
strFind = "[FullName] = " & Quote(objLink.Name)
Set objContact = colContacts.Find(strFind)
If Not objContact Is Nothing Then
' remove the old link
colLinks.Remove i
' add the replacement link
colLinks.Add objContact
End If
End If
Next
objItem.Save
End If
End If ' <<<< don't need this

Try deleting those two statements.

Also is the code actually executing the Debug.Print statement? Did you
display the Immediate window?

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


Michael Ray Brown said:
I took your advice, and added the statement to list the items and their
link
counts. When I run the macro, though, nothing shows up. To make sure
I've
got it right, I'm pasting the entire script below. Please forgive the
long
post.

--
Michael

-------------------------------------------

Sub FixContactLinks()
Dim objNS As NameSpace
Dim objFolder As MAPIFolder
Dim colItems As Items
Dim objItem As Object
Dim colLinks As Links
Dim objLink As Link
Dim colContacts As Items
Dim objContact As ContactItem
Dim strFind As String
Dim intCount As Integer
On Error Resume Next
Set objNS = Application.Session
Set objFolder = objNS.PickFolder
If Not objFolder Is Nothing Then
Set colContacts = _
objNS.GetDefaultFolder(olFolderContacts).Items
Set colItems = objFolder.Items
For Each objItem In colItems
Debug.Print objItem.Subject, objItem.Links.Count
If objItem.Class = olContact Then
Set colLinks = objItem.Links
intCount = colLinks.Count
If intCount > 0 Then
For i = intCount To 1 Step -1
Set objLink = colLinks.Item(i)
If objLink.Item Is Nothing Then
strFind = "[FullName] = " & Quote(objLink.Name)
Set objContact = colContacts.Find(strFind)
If Not objContact Is Nothing Then
' remove the old link
colLinks.Remove i
' add the replacement link
colLinks.Add objContact
End If
End If
Next
objItem.Save
End If
End If
Next
End If
Set objLink = Nothing
Set colLinks = Nothing
Set objItem = Nothing
Set objItems = Nothing
Set objFolder = Nothing
Set objNS = Nothing
Set objContact = Nothing
Set objApp = Nothing
End Sub
Function Quote(val) As String
Quote = Chr(34) & CStr(val) & Chr(34)
End Function

---------------------------------------------
Sue Mosher said:
Well, it must be missing something because all my Journal items, Calendar
items, and Task items have links to at least one Contact.

All I can say is that intCount is derived from the Count property of the
Links collection on the item being processed. You can add a Debug.Print
objItem.Subject, objItem.Links.Count statement inside the For Each loop to
get a list of the items and their link counts. The list will show in the
immediate window.
Just so I'm clear on how to run the macro: When it asks me to choose a
folder, I select the folder that contains the items which need to be
re-linked to a contact record.

Yes, that's correct.
If I decipher the macro correctly, it
defaults to the Contacts folder if no folder is selected, meaning that it
looks for links to other contacts in each contact record.

No, if no folder is selected, no items will be processed at all.

The code looks for matching contacts only in the user's default Contacts
folder, not in any other contacts folders that might be present.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers

--
Michael

That means that intCount equals zero, that the item being worked on has
no
contact links.

Michael Ray Brown said:
I'm a bit out of my depth here. I'm a writer, not a programmer.
However,
when I press "F8" to step through the script, it gets to the line...

If intCount > 0 Then

... and then the highlighting jumps to...

End If

It does this over and over again. I never see any link being added or
removed.

--
Michael

What happens if you step through the code in the debugger? Can you see
it
execute the statements where it adds a link, removes the old link, and
saves
the item?

I've unfortunately had the same catastrophe befall me. After upgrading
to
Outlook 2007 and running the recent patch, all the links to my Contacts
from
my Journal items, Task items, and Calendar items suddenly went dead.

I copied and pasted the VBA script into Outlook, and ran the macro, but
nothing has changed. Whenever I double click on a name in a Journal
item's
"Contacts" field, for example, I still get an error message:

"Cannot perform the requested operation. The command selected is not
valid
for this recipient. An internal support function returned an error."

--
Michael

The underscore is a continuation character. If you put the entire
statement
on one line, you must take the underscore out. If you leave it in, the
quotation mark needs to be after the equals sign.
I tried the ReconnectLinks () from Listing 20.2 and I keep getting an
error
at the line which is as follows;
If objLink.item Is Nothing Then
strFind = "[FullName] = _
" & Quote(objLink.Name)

If I type it as written then I get an compile error for unexpected end
of
statement because I hit return after the "_". If it keep the 3rd line
as
part of the 2nd line so that it looks as follows;
strFind = "[FullName] = _" & Quote(objLink.Name)
then I get an error when running it that Sub or Function is not
defined
and
it focuses on this line.
 
S

Sue Mosher [MVP-Outlook]

I have no idea what the problem might be. Maybe it's a weird timing issue. You could try pressing F9 to put a breakpoint on the For Each statement, then press F5 each time to loop back to the breakpoint.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


Michael Ray Brown said:
That did the trick! I ran it on my Journal items and Task items, and all
the links now work. Wow! Thank you!

Unfortunately, I still have problems with Calendar items. For some strange
reason, when I run the macro on the Calendar folder, it doesn't fix the
links. However, when I step through the macro, it seems to work. I see an
appointment item come up in the Immediate window, showing the number of
links, and when I go to that appointment and double-click on the link, it
works.

I'd step through the whole calendar, item-by-item, but that's a lot of "F8"
keystrokes. Can you see why the macro doesn't work on Calendar items?

--
Michael

I see one problem. This particular code will only update contacts because of
the first and last statements in this snippet:

If objItem.Class = olContact Then ' <<<< don't need this
Set colLinks = objItem.Links
intCount = colLinks.Count
If intCount > 0 Then
For i = intCount To 1 Step -1
Set objLink = colLinks.Item(i)
If objLink.Item Is Nothing Then
strFind = "[FullName] = " & Quote(objLink.Name)
Set objContact = colContacts.Find(strFind)
If Not objContact Is Nothing Then
' remove the old link
colLinks.Remove i
' add the replacement link
colLinks.Add objContact
End If
End If
Next
objItem.Save
End If
End If ' <<<< don't need this

Try deleting those two statements.

Also is the code actually executing the Debug.Print statement? Did you
display the Immediate window?

Michael Ray Brown said:
I took your advice, and added the statement to list the items and their
link
counts. When I run the macro, though, nothing shows up. To make sure
I've
got it right, I'm pasting the entire script below. Please forgive the
long
post.

--
Michael

-------------------------------------------

Sub FixContactLinks()
Dim objNS As NameSpace
Dim objFolder As MAPIFolder
Dim colItems As Items
Dim objItem As Object
Dim colLinks As Links
Dim objLink As Link
Dim colContacts As Items
Dim objContact As ContactItem
Dim strFind As String
Dim intCount As Integer
On Error Resume Next
Set objNS = Application.Session
Set objFolder = objNS.PickFolder
If Not objFolder Is Nothing Then
Set colContacts = _
objNS.GetDefaultFolder(olFolderContacts).Items
Set colItems = objFolder.Items
For Each objItem In colItems
Debug.Print objItem.Subject, objItem.Links.Count
If objItem.Class = olContact Then
Set colLinks = objItem.Links
intCount = colLinks.Count
If intCount > 0 Then
For i = intCount To 1 Step -1
Set objLink = colLinks.Item(i)
If objLink.Item Is Nothing Then
strFind = "[FullName] = " & Quote(objLink.Name)
Set objContact = colContacts.Find(strFind)
If Not objContact Is Nothing Then
' remove the old link
colLinks.Remove i
' add the replacement link
colLinks.Add objContact
End If
End If
Next
objItem.Save
End If
End If
Next
End If
Set objLink = Nothing
Set colLinks = Nothing
Set objItem = Nothing
Set objItems = Nothing
Set objFolder = Nothing
Set objNS = Nothing
Set objContact = Nothing
Set objApp = Nothing
End Sub
Function Quote(val) As String
Quote = Chr(34) & CStr(val) & Chr(34)
End Function

---------------------------------------------
Sue Mosher said:
Well, it must be missing something because all my Journal items, Calendar
items, and Task items have links to at least one Contact.

All I can say is that intCount is derived from the Count property of the
Links collection on the item being processed. You can add a Debug.Print
objItem.Subject, objItem.Links.Count statement inside the For Each loop to
get a list of the items and their link counts. The list will show in the
immediate window.
Just so I'm clear on how to run the macro: When it asks me to choose a
folder, I select the folder that contains the items which need to be
re-linked to a contact record.

Yes, that's correct.
If I decipher the macro correctly, it
defaults to the Contacts folder if no folder is selected, meaning that it
looks for links to other contacts in each contact record.

No, if no folder is selected, no items will be processed at all.

The code looks for matching contacts only in the user's default Contacts
folder, not in any other contacts folders that might be present.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers

--
Michael

That means that intCount equals zero, that the item being worked on has
no
contact links.

I'm a bit out of my depth here. I'm a writer, not a programmer.
However,
when I press "F8" to step through the script, it gets to the line...

If intCount > 0 Then

... and then the highlighting jumps to...

End If

It does this over and over again. I never see any link being added or
removed.

--
Michael

What happens if you step through the code in the debugger? Can you see
it
execute the statements where it adds a link, removes the old link, and
saves
the item?

I've unfortunately had the same catastrophe befall me. After upgrading
to
Outlook 2007 and running the recent patch, all the links to my Contacts
from
my Journal items, Task items, and Calendar items suddenly went dead.

I copied and pasted the VBA script into Outlook, and ran the macro, but
nothing has changed. Whenever I double click on a name in a Journal
item's
"Contacts" field, for example, I still get an error message:

"Cannot perform the requested operation. The command selected is not
valid
for this recipient. An internal support function returned an error."

--
Michael

The underscore is a continuation character. If you put the entire
statement
on one line, you must take the underscore out. If you leave it in, the
quotation mark needs to be after the equals sign.


I tried the ReconnectLinks () from Listing 20.2 and I keep getting an
error
at the line which is as follows;
If objLink.item Is Nothing Then
strFind = "[FullName] = _
" & Quote(objLink.Name)

If I type it as written then I get an compile error for unexpected end
of
statement because I hit return after the "_". If it keep the 3rd line
as
part of the 2nd line so that it looks as follows;
strFind = "[FullName] = _" & Quote(objLink.Name)
then I get an error when running it that Sub or Function is not
defined
and
it focuses on this line.
 
M

Michael Ray Brown

Okay, I put a breakpoint on the "For Each" statement, and pressed "F5."
Instead of cycling through just one item, the macro ran through the entire
Calendar folder. I could see a flood of items come up in the Immediate
window before the screen went white for about five seconds. When the
Project window reappeared and the dust settled, all I could find in the
Immediate window were holiday and birthday items.

And again, the links weren't fixed. Not even the ones connected with
birthdays.

If I could hire a robot to press "F8" for a day, that's what I'd do.

--
Michael

I have no idea what the problem might be. Maybe it's a weird timing issue.
You could try pressing F9 to put a breakpoint on the For Each statement,
then press F5 each time to loop back to the breakpoint.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


Michael Ray Brown said:
That did the trick! I ran it on my Journal items and Task items, and all
the links now work. Wow! Thank you!

Unfortunately, I still have problems with Calendar items. For some
strange
reason, when I run the macro on the Calendar folder, it doesn't fix the
links. However, when I step through the macro, it seems to work. I see
an
appointment item come up in the Immediate window, showing the number of
links, and when I go to that appointment and double-click on the link, it
works.

I'd step through the whole calendar, item-by-item, but that's a lot of
"F8"
keystrokes. Can you see why the macro doesn't work on Calendar items?

--
Michael

I see one problem. This particular code will only update contacts because
of
the first and last statements in this snippet:

If objItem.Class = olContact Then ' <<<< don't need this
Set colLinks = objItem.Links
intCount = colLinks.Count
If intCount > 0 Then
For i = intCount To 1 Step -1
Set objLink = colLinks.Item(i)
If objLink.Item Is Nothing Then
strFind = "[FullName] = " & Quote(objLink.Name)
Set objContact = colContacts.Find(strFind)
If Not objContact Is Nothing Then
' remove the old link
colLinks.Remove i
' add the replacement link
colLinks.Add objContact
End If
End If
Next
objItem.Save
End If
End If ' <<<< don't need this

Try deleting those two statements.

Also is the code actually executing the Debug.Print statement? Did you
display the Immediate window?

Michael Ray Brown said:
I took your advice, and added the statement to list the items and their
link
counts. When I run the macro, though, nothing shows up. To make sure
I've
got it right, I'm pasting the entire script below. Please forgive the
long
post.

--
Michael

-------------------------------------------

Sub FixContactLinks()
Dim objNS As NameSpace
Dim objFolder As MAPIFolder
Dim colItems As Items
Dim objItem As Object
Dim colLinks As Links
Dim objLink As Link
Dim colContacts As Items
Dim objContact As ContactItem
Dim strFind As String
Dim intCount As Integer
On Error Resume Next
Set objNS = Application.Session
Set objFolder = objNS.PickFolder
If Not objFolder Is Nothing Then
Set colContacts = _
objNS.GetDefaultFolder(olFolderContacts).Items
Set colItems = objFolder.Items
For Each objItem In colItems
Debug.Print objItem.Subject, objItem.Links.Count
If objItem.Class = olContact Then
Set colLinks = objItem.Links
intCount = colLinks.Count
If intCount > 0 Then
For i = intCount To 1 Step -1
Set objLink = colLinks.Item(i)
If objLink.Item Is Nothing Then
strFind = "[FullName] = " &
Quote(objLink.Name)
Set objContact = colContacts.Find(strFind)
If Not objContact Is Nothing Then
' remove the old link
colLinks.Remove i
' add the replacement link
colLinks.Add objContact
End If
End If
Next
objItem.Save
End If
End If
Next
End If
Set objLink = Nothing
Set colLinks = Nothing
Set objItem = Nothing
Set objItems = Nothing
Set objFolder = Nothing
Set objNS = Nothing
Set objContact = Nothing
Set objApp = Nothing
End Sub
Function Quote(val) As String
Quote = Chr(34) & CStr(val) & Chr(34)
End Function

---------------------------------------------
Sue Mosher said:
Well, it must be missing something because all my Journal items,
Calendar
items, and Task items have links to at least one Contact.

All I can say is that intCount is derived from the Count property of the
Links collection on the item being processed. You can add a Debug.Print
objItem.Subject, objItem.Links.Count statement inside the For Each loop
to
get a list of the items and their link counts. The list will show in the
immediate window.
Just so I'm clear on how to run the macro: When it asks me to choose a
folder, I select the folder that contains the items which need to be
re-linked to a contact record.

Yes, that's correct.
If I decipher the macro correctly, it
defaults to the Contacts folder if no folder is selected, meaning that
it
looks for links to other contacts in each contact record.

No, if no folder is selected, no items will be processed at all.

The code looks for matching contacts only in the user's default Contacts
folder, not in any other contacts folders that might be present.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers

--
Michael

That means that intCount equals zero, that the item being worked on has
no
contact links.

I'm a bit out of my depth here. I'm a writer, not a programmer.
However,
when I press "F8" to step through the script, it gets to the line...

If intCount > 0 Then

... and then the highlighting jumps to...

End If

It does this over and over again. I never see any link being added or
removed.

--
Michael

What happens if you step through the code in the debugger? Can you see
it
execute the statements where it adds a link, removes the old link, and
saves
the item?

I've unfortunately had the same catastrophe befall me. After
upgrading
to
Outlook 2007 and running the recent patch, all the links to my
Contacts
from
my Journal items, Task items, and Calendar items suddenly went dead.

I copied and pasted the VBA script into Outlook, and ran the macro,
but
nothing has changed. Whenever I double click on a name in a Journal
item's
"Contacts" field, for example, I still get an error message:

"Cannot perform the requested operation. The command selected is not
valid
for this recipient. An internal support function returned an error."

--
Michael

The underscore is a continuation character. If you put the entire
statement
on one line, you must take the underscore out. If you leave it in, the
quotation mark needs to be after the equals sign.


I tried the ReconnectLinks () from Listing 20.2 and I keep getting an
error
at the line which is as follows;
If objLink.item Is Nothing Then
strFind = "[FullName] = _
" & Quote(objLink.Name)

If I type it as written then I get an compile error for unexpected
end
of
statement because I hit return after the "_". If it keep the 3rd
line
as
part of the 2nd line so that it looks as follows;
strFind = "[FullName] = _" & Quote(objLink.Name)
then I get an error when running it that Sub or Function is not
defined
and
it focuses on this line.
 
S

Sue Mosher [MVP-Outlook]

The breakpoint must not be in the right place, because wherever there is a breakpoint, the code will stop every time it reaches that point. What I'm trying to do is get your loop to run once for one item, then stop, so you can then press F5 to process the next item.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


Michael Ray Brown said:
Okay, I put a breakpoint on the "For Each" statement, and pressed "F5."
Instead of cycling through just one item, the macro ran through the entire
Calendar folder. I could see a flood of items come up in the Immediate
window before the screen went white for about five seconds. When the
Project window reappeared and the dust settled, all I could find in the
Immediate window were holiday and birthday items.

And again, the links weren't fixed. Not even the ones connected with
birthdays.

If I could hire a robot to press "F8" for a day, that's what I'd do.

--
Michael

I have no idea what the problem might be. Maybe it's a weird timing issue.
You could try pressing F9 to put a breakpoint on the For Each statement,
then press F5 each time to loop back to the breakpoint.
Michael Ray Brown said:
That did the trick! I ran it on my Journal items and Task items, and all
the links now work. Wow! Thank you!

Unfortunately, I still have problems with Calendar items. For some
strange
reason, when I run the macro on the Calendar folder, it doesn't fix the
links. However, when I step through the macro, it seems to work. I see
an
appointment item come up in the Immediate window, showing the number of
links, and when I go to that appointment and double-click on the link, it
works.

I'd step through the whole calendar, item-by-item, but that's a lot of
"F8"
keystrokes. Can you see why the macro doesn't work on Calendar items?

--
Michael

I see one problem. This particular code will only update contacts because
of
the first and last statements in this snippet:

If objItem.Class = olContact Then ' <<<< don't need this
Set colLinks = objItem.Links
intCount = colLinks.Count
If intCount > 0 Then
For i = intCount To 1 Step -1
Set objLink = colLinks.Item(i)
If objLink.Item Is Nothing Then
strFind = "[FullName] = " & Quote(objLink.Name)
Set objContact = colContacts.Find(strFind)
If Not objContact Is Nothing Then
' remove the old link
colLinks.Remove i
' add the replacement link
colLinks.Add objContact
End If
End If
Next
objItem.Save
End If
End If ' <<<< don't need this

Try deleting those two statements.

Also is the code actually executing the Debug.Print statement? Did you
display the Immediate window?

Michael Ray Brown said:
I took your advice, and added the statement to list the items and their
link
counts. When I run the macro, though, nothing shows up. To make sure
I've
got it right, I'm pasting the entire script below. Please forgive the
long
post.

--
Michael

-------------------------------------------

Sub FixContactLinks()
Dim objNS As NameSpace
Dim objFolder As MAPIFolder
Dim colItems As Items
Dim objItem As Object
Dim colLinks As Links
Dim objLink As Link
Dim colContacts As Items
Dim objContact As ContactItem
Dim strFind As String
Dim intCount As Integer
On Error Resume Next
Set objNS = Application.Session
Set objFolder = objNS.PickFolder
If Not objFolder Is Nothing Then
Set colContacts = _
objNS.GetDefaultFolder(olFolderContacts).Items
Set colItems = objFolder.Items
For Each objItem In colItems
Debug.Print objItem.Subject, objItem.Links.Count
If objItem.Class = olContact Then
Set colLinks = objItem.Links
intCount = colLinks.Count
If intCount > 0 Then
For i = intCount To 1 Step -1
Set objLink = colLinks.Item(i)
If objLink.Item Is Nothing Then
strFind = "[FullName] = " &
Quote(objLink.Name)
Set objContact = colContacts.Find(strFind)
If Not objContact Is Nothing Then
' remove the old link
colLinks.Remove i
' add the replacement link
colLinks.Add objContact
End If
End If
Next
objItem.Save
End If
End If
Next
End If
Set objLink = Nothing
Set colLinks = Nothing
Set objItem = Nothing
Set objItems = Nothing
Set objFolder = Nothing
Set objNS = Nothing
Set objContact = Nothing
Set objApp = Nothing
End Sub
Function Quote(val) As String
Quote = Chr(34) & CStr(val) & Chr(34)
End Function

---------------------------------------------
Well, it must be missing something because all my Journal items,
Calendar
items, and Task items have links to at least one Contact.

All I can say is that intCount is derived from the Count property of the
Links collection on the item being processed. You can add a Debug.Print
objItem.Subject, objItem.Links.Count statement inside the For Each loop
to
get a list of the items and their link counts. The list will show in the
immediate window.

Just so I'm clear on how to run the macro: When it asks me to choose a
folder, I select the folder that contains the items which need to be
re-linked to a contact record.

Yes, that's correct.

If I decipher the macro correctly, it
defaults to the Contacts folder if no folder is selected, meaning that
it
looks for links to other contacts in each contact record.

No, if no folder is selected, no items will be processed at all.

The code looks for matching contacts only in the user's default Contacts
folder, not in any other contacts folders that might be present.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



--
Michael

That means that intCount equals zero, that the item being worked on has
no
contact links.

I'm a bit out of my depth here. I'm a writer, not a programmer.
However,
when I press "F8" to step through the script, it gets to the line...

If intCount > 0 Then

... and then the highlighting jumps to...

End If

It does this over and over again. I never see any link being added or
removed.

--
Michael

What happens if you step through the code in the debugger? Can you see
it
execute the statements where it adds a link, removes the old link, and
saves
the item?

I've unfortunately had the same catastrophe befall me. After
upgrading
to
Outlook 2007 and running the recent patch, all the links to my
Contacts
from
my Journal items, Task items, and Calendar items suddenly went dead.

I copied and pasted the VBA script into Outlook, and ran the macro,
but
nothing has changed. Whenever I double click on a name in a Journal
item's
"Contacts" field, for example, I still get an error message:

"Cannot perform the requested operation. The command selected is not
valid
for this recipient. An internal support function returned an error."

--
Michael

The underscore is a continuation character. If you put the entire
statement
on one line, you must take the underscore out. If you leave it in, the
quotation mark needs to be after the equals sign.


I tried the ReconnectLinks () from Listing 20.2 and I keep getting an
error
at the line which is as follows;
If objLink.item Is Nothing Then
strFind = "[FullName] = _
" & Quote(objLink.Name)

If I type it as written then I get an compile error for unexpected
end
of
statement because I hit return after the "_". If it keep the 3rd
line
as
part of the 2nd line so that it looks as follows;
strFind = "[FullName] = _" & Quote(objLink.Name)
then I get an error when running it that Sub or Function is not
defined
and
it focuses on this line.
 
M

Michael Ray Brown

I tried inserting the breakpoint on the line following the "For Each"
statement. This time it didn't cycle through the entire Calendar folder,
but went through each item individually when I hit "F5." However, it
changed nothing. The links still do not work. And with more than 12 years'
appointments in my Calendar, my finger is getting a little sore.

--
Michael

The breakpoint must not be in the right place, because wherever there is a
breakpoint, the code will stop every time it reaches that point. What I'm
trying to do is get your loop to run once for one item, then stop, so you
can then press F5 to process the next item.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


Michael Ray Brown said:
Okay, I put a breakpoint on the "For Each" statement, and pressed "F5."
Instead of cycling through just one item, the macro ran through the entire
Calendar folder. I could see a flood of items come up in the Immediate
window before the screen went white for about five seconds. When the
Project window reappeared and the dust settled, all I could find in the
Immediate window were holiday and birthday items.

And again, the links weren't fixed. Not even the ones connected with
birthdays.

If I could hire a robot to press "F8" for a day, that's what I'd do.

--
Michael

I have no idea what the problem might be. Maybe it's a weird timing issue.
You could try pressing F9 to put a breakpoint on the For Each statement,
then press F5 each time to loop back to the breakpoint.
Michael Ray Brown said:
That did the trick! I ran it on my Journal items and Task items, and all
the links now work. Wow! Thank you!

Unfortunately, I still have problems with Calendar items. For some
strange
reason, when I run the macro on the Calendar folder, it doesn't fix the
links. However, when I step through the macro, it seems to work. I see
an
appointment item come up in the Immediate window, showing the number of
links, and when I go to that appointment and double-click on the link, it
works.

I'd step through the whole calendar, item-by-item, but that's a lot of
"F8"
keystrokes. Can you see why the macro doesn't work on Calendar items?

--
Michael

I see one problem. This particular code will only update contacts because
of
the first and last statements in this snippet:

If objItem.Class = olContact Then ' <<<< don't need this
Set colLinks = objItem.Links
intCount = colLinks.Count
If intCount > 0 Then
For i = intCount To 1 Step -1
Set objLink = colLinks.Item(i)
If objLink.Item Is Nothing Then
strFind = "[FullName] = " &
Quote(objLink.Name)
Set objContact = colContacts.Find(strFind)
If Not objContact Is Nothing Then
' remove the old link
colLinks.Remove i
' add the replacement link
colLinks.Add objContact
End If
End If
Next
objItem.Save
End If
End If ' <<<< don't need this

Try deleting those two statements.

Also is the code actually executing the Debug.Print statement? Did you
display the Immediate window?

Michael Ray Brown said:
I took your advice, and added the statement to list the items and their
link
counts. When I run the macro, though, nothing shows up. To make sure
I've
got it right, I'm pasting the entire script below. Please forgive the
long
post.

--
Michael

-------------------------------------------

Sub FixContactLinks()
Dim objNS As NameSpace
Dim objFolder As MAPIFolder
Dim colItems As Items
Dim objItem As Object
Dim colLinks As Links
Dim objLink As Link
Dim colContacts As Items
Dim objContact As ContactItem
Dim strFind As String
Dim intCount As Integer
On Error Resume Next
Set objNS = Application.Session
Set objFolder = objNS.PickFolder
If Not objFolder Is Nothing Then
Set colContacts = _
objNS.GetDefaultFolder(olFolderContacts).Items
Set colItems = objFolder.Items
For Each objItem In colItems
Debug.Print objItem.Subject, objItem.Links.Count
If objItem.Class = olContact Then
Set colLinks = objItem.Links
intCount = colLinks.Count
If intCount > 0 Then
For i = intCount To 1 Step -1
Set objLink = colLinks.Item(i)
If objLink.Item Is Nothing Then
strFind = "[FullName] = " &
Quote(objLink.Name)
Set objContact = colContacts.Find(strFind)
If Not objContact Is Nothing Then
' remove the old link
colLinks.Remove i
' add the replacement link
colLinks.Add objContact
End If
End If
Next
objItem.Save
End If
End If
Next
End If
Set objLink = Nothing
Set colLinks = Nothing
Set objItem = Nothing
Set objItems = Nothing
Set objFolder = Nothing
Set objNS = Nothing
Set objContact = Nothing
Set objApp = Nothing
End Sub
Function Quote(val) As String
Quote = Chr(34) & CStr(val) & Chr(34)
End Function

---------------------------------------------
Well, it must be missing something because all my Journal items,
Calendar
items, and Task items have links to at least one Contact.

All I can say is that intCount is derived from the Count property of the
Links collection on the item being processed. You can add a Debug.Print
objItem.Subject, objItem.Links.Count statement inside the For Each loop
to
get a list of the items and their link counts. The list will show in the
immediate window.

Just so I'm clear on how to run the macro: When it asks me to choose a
folder, I select the folder that contains the items which need to be
re-linked to a contact record.

Yes, that's correct.

If I decipher the macro correctly, it
defaults to the Contacts folder if no folder is selected, meaning that
it
looks for links to other contacts in each contact record.

No, if no folder is selected, no items will be processed at all.

The code looks for matching contacts only in the user's default Contacts
folder, not in any other contacts folders that might be present.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



--
Michael

That means that intCount equals zero, that the item being worked on has
no
contact links.

I'm a bit out of my depth here. I'm a writer, not a programmer.
However,
when I press "F8" to step through the script, it gets to the line...

If intCount > 0 Then

... and then the highlighting jumps to...

End If

It does this over and over again. I never see any link being added or
removed.

--
Michael

What happens if you step through the code in the debugger? Can you see
it
execute the statements where it adds a link, removes the old link, and
saves
the item?

message
I've unfortunately had the same catastrophe befall me. After
upgrading
to
Outlook 2007 and running the recent patch, all the links to my
Contacts
from
my Journal items, Task items, and Calendar items suddenly went dead.

I copied and pasted the VBA script into Outlook, and ran the macro,
but
nothing has changed. Whenever I double click on a name in a Journal
item's
"Contacts" field, for example, I still get an error message:

"Cannot perform the requested operation. The command selected is not
valid
for this recipient. An internal support function returned an error."

--
Michael

The underscore is a continuation character. If you put the entire
statement
on one line, you must take the underscore out. If you leave it in,
the
quotation mark needs to be after the equals sign.


I tried the ReconnectLinks () from Listing 20.2 and I keep getting an
error
at the line which is as follows;
If objLink.item Is Nothing Then
strFind = "[FullName] = _
" & Quote(objLink.Name)

If I type it as written then I get an compile error for unexpected
end
of
statement because I hit return after the "_". If it keep the 3rd
line
as
part of the 2nd line so that it looks as follows;
strFind = "[FullName] = _" & Quote(objLink.Name)
then I get an error when running it that Sub or Function is not
defined
and
it focuses on this line.
 
S

Sue Mosher [MVP-Outlook]

Are the contacts that need to be relinked located in your default Contacts folder? If not, then we'll have to modify the code to add another PickFolder statement to allow you to select where they're located.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


Michael Ray Brown said:
I tried inserting the breakpoint on the line following the "For Each"
statement. This time it didn't cycle through the entire Calendar folder,
but went through each item individually when I hit "F5." However, it
changed nothing. The links still do not work. And with more than 12 years'
appointments in my Calendar, my finger is getting a little sore.

--
Michael

The breakpoint must not be in the right place, because wherever there is a
breakpoint, the code will stop every time it reaches that point. What I'm
trying to do is get your loop to run once for one item, then stop, so you
can then press F5 to process the next item.
Michael Ray Brown said:
Okay, I put a breakpoint on the "For Each" statement, and pressed "F5."
Instead of cycling through just one item, the macro ran through the entire
Calendar folder. I could see a flood of items come up in the Immediate
window before the screen went white for about five seconds. When the
Project window reappeared and the dust settled, all I could find in the
Immediate window were holiday and birthday items.

And again, the links weren't fixed. Not even the ones connected with
birthdays.

If I could hire a robot to press "F8" for a day, that's what I'd do.

--
Michael

I have no idea what the problem might be. Maybe it's a weird timing issue.
You could try pressing F9 to put a breakpoint on the For Each statement,
then press F5 each time to loop back to the breakpoint.
Michael Ray Brown said:
That did the trick! I ran it on my Journal items and Task items, and all
the links now work. Wow! Thank you!

Unfortunately, I still have problems with Calendar items. For some
strange
reason, when I run the macro on the Calendar folder, it doesn't fix the
links. However, when I step through the macro, it seems to work. I see
an
appointment item come up in the Immediate window, showing the number of
links, and when I go to that appointment and double-click on the link, it
works.

I'd step through the whole calendar, item-by-item, but that's a lot of
"F8"
keystrokes. Can you see why the macro doesn't work on Calendar items?

--
Michael

I see one problem. This particular code will only update contacts because
of
the first and last statements in this snippet:

If objItem.Class = olContact Then ' <<<< don't need this
Set colLinks = objItem.Links
intCount = colLinks.Count
If intCount > 0 Then
For i = intCount To 1 Step -1
Set objLink = colLinks.Item(i)
If objLink.Item Is Nothing Then
strFind = "[FullName] = " &
Quote(objLink.Name)
Set objContact = colContacts.Find(strFind)
If Not objContact Is Nothing Then
' remove the old link
colLinks.Remove i
' add the replacement link
colLinks.Add objContact
End If
End If
Next
objItem.Save
End If
End If ' <<<< don't need this

Try deleting those two statements.

Also is the code actually executing the Debug.Print statement? Did you
display the Immediate window?

I took your advice, and added the statement to list the items and their
link
counts. When I run the macro, though, nothing shows up. To make sure
I've
got it right, I'm pasting the entire script below. Please forgive the
long
post.

--
Michael

-------------------------------------------

Sub FixContactLinks()
Dim objNS As NameSpace
Dim objFolder As MAPIFolder
Dim colItems As Items
Dim objItem As Object
Dim colLinks As Links
Dim objLink As Link
Dim colContacts As Items
Dim objContact As ContactItem
Dim strFind As String
Dim intCount As Integer
On Error Resume Next
Set objNS = Application.Session
Set objFolder = objNS.PickFolder
If Not objFolder Is Nothing Then
Set colContacts = _
objNS.GetDefaultFolder(olFolderContacts).Items
Set colItems = objFolder.Items
For Each objItem In colItems
Debug.Print objItem.Subject, objItem.Links.Count
If objItem.Class = olContact Then
Set colLinks = objItem.Links
intCount = colLinks.Count
If intCount > 0 Then
For i = intCount To 1 Step -1
Set objLink = colLinks.Item(i)
If objLink.Item Is Nothing Then
strFind = "[FullName] = " &
Quote(objLink.Name)
Set objContact = colContacts.Find(strFind)
If Not objContact Is Nothing Then
' remove the old link
colLinks.Remove i
' add the replacement link
colLinks.Add objContact
End If
End If
Next
objItem.Save
End If
End If
Next
End If
Set objLink = Nothing
Set colLinks = Nothing
Set objItem = Nothing
Set objItems = Nothing
Set objFolder = Nothing
Set objNS = Nothing
Set objContact = Nothing
Set objApp = Nothing
End Sub
Function Quote(val) As String
Quote = Chr(34) & CStr(val) & Chr(34)
End Function

---------------------------------------------
Well, it must be missing something because all my Journal items,
Calendar
items, and Task items have links to at least one Contact.

All I can say is that intCount is derived from the Count property of the
Links collection on the item being processed. You can add a Debug.Print
objItem.Subject, objItem.Links.Count statement inside the For Each loop
to
get a list of the items and their link counts. The list will show in the
immediate window.

Just so I'm clear on how to run the macro: When it asks me to choose a
folder, I select the folder that contains the items which need to be
re-linked to a contact record.

Yes, that's correct.

If I decipher the macro correctly, it
defaults to the Contacts folder if no folder is selected, meaning that
it
looks for links to other contacts in each contact record.

No, if no folder is selected, no items will be processed at all.

The code looks for matching contacts only in the user's default Contacts
folder, not in any other contacts folders that might be present.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



--
Michael

That means that intCount equals zero, that the item being worked on has
no
contact links.

I'm a bit out of my depth here. I'm a writer, not a programmer.
However,
when I press "F8" to step through the script, it gets to the line...

If intCount > 0 Then

... and then the highlighting jumps to...

End If

It does this over and over again. I never see any link being added or
removed.

--
Michael

What happens if you step through the code in the debugger? Can you see
it
execute the statements where it adds a link, removes the old link, and
saves
the item?

message
I've unfortunately had the same catastrophe befall me. After
upgrading
to
Outlook 2007 and running the recent patch, all the links to my
Contacts
from
my Journal items, Task items, and Calendar items suddenly went dead.

I copied and pasted the VBA script into Outlook, and ran the macro,
but
nothing has changed. Whenever I double click on a name in a Journal
item's
"Contacts" field, for example, I still get an error message:

"Cannot perform the requested operation. The command selected is not
valid
for this recipient. An internal support function returned an error."

--
Michael

The underscore is a continuation character. If you put the entire
statement
on one line, you must take the underscore out. If you leave it in,
the
quotation mark needs to be after the equals sign.


I tried the ReconnectLinks () from Listing 20.2 and I keep getting an
error
at the line which is as follows;
If objLink.item Is Nothing Then
strFind = "[FullName] = _
" & Quote(objLink.Name)

If I type it as written then I get an compile error for unexpected
end
of
statement because I hit return after the "_". If it keep the 3rd
line
as
part of the 2nd line so that it looks as follows;
strFind = "[FullName] = _" & Quote(objLink.Name)
then I get an error when running it that Sub or Function is not
defined
and
it focuses on this line.
 
M

Michael Ray Brown

Yes, my contacts are in the default Contacts folder. I can't understand why
the macro isn't re-linking the Calendar items. On all other types of
Outlook items it worked like a dream. The only thing different now is that
I'm selecting the Calendar folder. By the way, I'm very grateful for your
expertise and the time you've spent helping me resolve this issue.

--
Michael

Are the contacts that need to be relinked located in your default Contacts
folder? If not, then we'll have to modify the code to add another PickFolder
statement to allow you to select where they're located.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


Michael Ray Brown said:
I tried inserting the breakpoint on the line following the "For Each"
statement. This time it didn't cycle through the entire Calendar folder,
but went through each item individually when I hit "F5." However, it
changed nothing. The links still do not work. And with more than 12
years'
appointments in my Calendar, my finger is getting a little sore.

--
Michael

The breakpoint must not be in the right place, because wherever there is a
breakpoint, the code will stop every time it reaches that point. What I'm
trying to do is get your loop to run once for one item, then stop, so you
can then press F5 to process the next item.
Michael Ray Brown said:
Okay, I put a breakpoint on the "For Each" statement, and pressed "F5."
Instead of cycling through just one item, the macro ran through the
entire
Calendar folder. I could see a flood of items come up in the Immediate
window before the screen went white for about five seconds. When the
Project window reappeared and the dust settled, all I could find in the
Immediate window were holiday and birthday items.

And again, the links weren't fixed. Not even the ones connected with
birthdays.

If I could hire a robot to press "F8" for a day, that's what I'd do.

--
Michael

I have no idea what the problem might be. Maybe it's a weird timing
issue.
You could try pressing F9 to put a breakpoint on the For Each statement,
then press F5 each time to loop back to the breakpoint.
Michael Ray Brown said:
That did the trick! I ran it on my Journal items and Task items, and
all
the links now work. Wow! Thank you!

Unfortunately, I still have problems with Calendar items. For some
strange
reason, when I run the macro on the Calendar folder, it doesn't fix the
links. However, when I step through the macro, it seems to work. I see
an
appointment item come up in the Immediate window, showing the number of
links, and when I go to that appointment and double-click on the link,
it
works.

I'd step through the whole calendar, item-by-item, but that's a lot of
"F8"
keystrokes. Can you see why the macro doesn't work on Calendar items?

--
Michael

I see one problem. This particular code will only update contacts
because
of
the first and last statements in this snippet:

If objItem.Class = olContact Then ' <<<< don't need this
Set colLinks = objItem.Links
intCount = colLinks.Count
If intCount > 0 Then
For i = intCount To 1 Step -1
Set objLink = colLinks.Item(i)
If objLink.Item Is Nothing Then
strFind = "[FullName] = " &
Quote(objLink.Name)
Set objContact = colContacts.Find(strFind)
If Not objContact Is Nothing Then
' remove the old link
colLinks.Remove i
' add the replacement link
colLinks.Add objContact
End If
End If
Next
objItem.Save
End If
End If ' <<<< don't need this

Try deleting those two statements.

Also is the code actually executing the Debug.Print statement? Did you
display the Immediate window?

I took your advice, and added the statement to list the items and their
link
counts. When I run the macro, though, nothing shows up. To make sure
I've
got it right, I'm pasting the entire script below. Please forgive the
long
post.

--
Michael

-------------------------------------------

Sub FixContactLinks()
Dim objNS As NameSpace
Dim objFolder As MAPIFolder
Dim colItems As Items
Dim objItem As Object
Dim colLinks As Links
Dim objLink As Link
Dim colContacts As Items
Dim objContact As ContactItem
Dim strFind As String
Dim intCount As Integer
On Error Resume Next
Set objNS = Application.Session
Set objFolder = objNS.PickFolder
If Not objFolder Is Nothing Then
Set colContacts = _
objNS.GetDefaultFolder(olFolderContacts).Items
Set colItems = objFolder.Items
For Each objItem In colItems
Debug.Print objItem.Subject, objItem.Links.Count
If objItem.Class = olContact Then
Set colLinks = objItem.Links
intCount = colLinks.Count
If intCount > 0 Then
For i = intCount To 1 Step -1
Set objLink = colLinks.Item(i)
If objLink.Item Is Nothing Then
strFind = "[FullName] = " &
Quote(objLink.Name)
Set objContact = colContacts.Find(strFind)
If Not objContact Is Nothing Then
' remove the old link
colLinks.Remove i
' add the replacement link
colLinks.Add objContact
End If
End If
Next
objItem.Save
End If
End If
Next
End If
Set objLink = Nothing
Set colLinks = Nothing
Set objItem = Nothing
Set objItems = Nothing
Set objFolder = Nothing
Set objNS = Nothing
Set objContact = Nothing
Set objApp = Nothing
End Sub
Function Quote(val) As String
Quote = Chr(34) & CStr(val) & Chr(34)
End Function

---------------------------------------------
Well, it must be missing something because all my Journal items,
Calendar
items, and Task items have links to at least one Contact.

All I can say is that intCount is derived from the Count property of
the
Links collection on the item being processed. You can add a Debug.Print
objItem.Subject, objItem.Links.Count statement inside the For Each loop
to
get a list of the items and their link counts. The list will show in
the
immediate window.

Just so I'm clear on how to run the macro: When it asks me to choose
a
folder, I select the folder that contains the items which need to be
re-linked to a contact record.

Yes, that's correct.

If I decipher the macro correctly, it
defaults to the Contacts folder if no folder is selected, meaning that
it
looks for links to other contacts in each contact record.

No, if no folder is selected, no items will be processed at all.

The code looks for matching contacts only in the user's default
Contacts
folder, not in any other contacts folders that might be present.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



--
Michael

That means that intCount equals zero, that the item being worked on
has
no
contact links.

message
I'm a bit out of my depth here. I'm a writer, not a programmer.
However,
when I press "F8" to step through the script, it gets to the line...

If intCount > 0 Then

... and then the highlighting jumps to...

End If

It does this over and over again. I never see any link being added
or
removed.

--
Michael

What happens if you step through the code in the debugger? Can you
see
it
execute the statements where it adds a link, removes the old link,
and
saves
the item?

message
I've unfortunately had the same catastrophe befall me. After
upgrading
to
Outlook 2007 and running the recent patch, all the links to my
Contacts
from
my Journal items, Task items, and Calendar items suddenly went dead.

I copied and pasted the VBA script into Outlook, and ran the macro,
but
nothing has changed. Whenever I double click on a name in a Journal
item's
"Contacts" field, for example, I still get an error message:

"Cannot perform the requested operation. The command selected is not
valid
for this recipient. An internal support function returned an error."

--
Michael

The underscore is a continuation character. If you put the entire
statement
on one line, you must take the underscore out. If you leave it in,
the
quotation mark needs to be after the equals sign.


I tried the ReconnectLinks () from Listing 20.2 and I keep getting
an
error
at the line which is as follows;
If objLink.item Is Nothing Then
strFind = "[FullName] = _
" & Quote(objLink.Name)

If I type it as written then I get an compile error for unexpected
end
of
statement because I hit return after the "_". If it keep the 3rd
line
as
part of the 2nd line so that it looks as follows;
strFind = "[FullName] = _" & Quote(objLink.Name)
then I get an error when running it that Sub or Function is not
defined
and
it focuses on this line.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top