Problem copying contact

  • Thread starter Thread starter Pete Davis
  • Start date Start date
P

Pete Davis

I have the following code:

For Each oCurrContact In oMasterFolder.Items
If False = IsInFolder(oCurrContact, oDontSendFolder) Then
oCurrContact.Copy oSendFolder
End If
Next

oCurrContact is of type ContactItem. It is a valid item and in the debugger,
it's the contact I expect it to be. oSendFolder and oMasterFolder are
MAPIFolder objects.

In the oCurrContact.Copy oSendFolder call, I get a message that "The object
does not support this method."

Now, according to the typeahead, Copy is a perfectly legitimate method in
oCurrContact. What am I doing wrong?

In case it's any help, the entire subroutine is as follows:

Dim oMAPI As Outlook.NameSpace
Dim oParentFolder As MAPIFolder
Dim oFolder As MAPIFolder
Dim oMasterFolder As MAPIFolder
Dim oDontSendFolder As MAPIFolder
Dim oSendFolder As MAPIFolder
Dim oObject As Object
Dim oCurrContact As ContactItem

If masterComboBox.Text = "" Or dontSendComboBox.Text = "" Or
sendComboBox.Text = "" Then
MsgBox "You must set all folder"
Exit Sub
End If

Set oMAPI = GetObject("", "Outlook.application").GetNamespace("MAPI")
Set oParentFolder = oMAPI.Folders("Personal Folders")

For Each oFolder In oParentFolder.Folders
If oFolder.Name = masterComboBox.Text Then
Set oMasterFolder = oFolder
ElseIf oFolder.Name = dontSendComboBox.Text Then
Set oDontSendFolder = oFolder
ElseIf oFolder.Name = sendComboBox.Text Then
Set oSendFolder = oFolder
End If
Next

For Each oCurrContact In oSendFolder.Items
oCurrContact.Delete
Next

For Each oCurrContact In oMasterFolder.Items
If False = IsInFolder(oCurrContact, oDontSendFolder) Then
oCurrContact.Copy oSendFolder
End If
Next


Thanks.

Pete
 
Copy is a function and takes no argument. Try:

Set MyCopy = oCurrContact.Copy
Set MyMovedITem = MyCopy.Move(oSendFolder)

FWIW, you shouldn't iterate the contacts folder with an item object declared as ContactItem, since a contacts folder may also contain DistListItem objects as well. Declare the item as Object and check its Class property before you start using ContactItem-specific methods or properties.
--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 
That worked, thanks.

Yes, I thought about making it a bit safer, but on the other hand, it's
being used in a very controlled environment and it's a quick fix to help
someone out. There are actually several places where that could happen. They
need a quick solution. Robustness doesn't come into the picture. But thanks.

Pete


Copy is a function and takes no argument. Try:

Set MyCopy = oCurrContact.Copy
Set MyMovedITem = MyCopy.Move(oSendFolder)

FWIW, you shouldn't iterate the contacts folder with an item object declared
as ContactItem, since a contacts folder may also contain DistListItem
objects as well. Declare the item as Object and check its Class property
before you start using ContactItem-specific methods or properties.
--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 
Back
Top