I'm kind of rusty with VBA (it's been more than a couple of years), and would appreciate any help; we're cleaning up a data entry error.
In OL2019, I want to copy the values in the Anniversary field to a previously created custom field, InvoiceDate.
There doesn't seem to be a way to do this other than programmatically.
Ideally, I'd like to execute this action only for records where the Anniversary value was added or changed after June 1, 2022, but that may be hoping for too much.
I found a likely script on this forum and modified it.
It's throwing an error on the line
objItem.InvoiceDate = objItem.Anniversary
the error is 438, "Object doesn't support this property or method."
I'm guessing it has something to do with the custom field, but if that's correct, I have no idea where to go next.
Any suggestions would be greatly appreciated.
Sub CopyAniversaryToInvoiceDate()
Dim objNS As Outlook.NameSpace
Dim objItems As Items
Dim objItem As Object
Set objNS = Application.Session
Set objItems = objNS.GetDefaultFolder(olFolderContacts).Items
For Each objItem In objItems
' make sure you have a Contact item
If objItem.Class = olContact Then
' copy data
objItem.InvoiceDate = objItem.Anniversary
objItem.Save
End If
Next
Set objItems = Nothing
Set objItem = Nothing
Set objNS = Nothing
End Sub
In OL2019, I want to copy the values in the Anniversary field to a previously created custom field, InvoiceDate.
There doesn't seem to be a way to do this other than programmatically.
Ideally, I'd like to execute this action only for records where the Anniversary value was added or changed after June 1, 2022, but that may be hoping for too much.
I found a likely script on this forum and modified it.
It's throwing an error on the line
objItem.InvoiceDate = objItem.Anniversary
the error is 438, "Object doesn't support this property or method."
I'm guessing it has something to do with the custom field, but if that's correct, I have no idea where to go next.
Any suggestions would be greatly appreciated.
Sub CopyAniversaryToInvoiceDate()
Dim objNS As Outlook.NameSpace
Dim objItems As Items
Dim objItem As Object
Set objNS = Application.Session
Set objItems = objNS.GetDefaultFolder(olFolderContacts).Items
For Each objItem In objItems
' make sure you have a Contact item
If objItem.Class = olContact Then
' copy data
objItem.InvoiceDate = objItem.Anniversary
objItem.Save
End If
Next
Set objItems = Nothing
Set objItem = Nothing
Set objNS = Nothing
End Sub