import to custom form

S

SLP

Hi, After reading lots of posts, I copied the code as follows but when I
import it goes to the default form and the "Billing Information" does not get
placed in User1. I keep starring at the code and don't know what to do. Any
help would be appreciated. Thanks.

Sub ConvertFields()
Dim objApp As Application
Dim objNS As NameSpace
Dim objFolder As MAPIFolder
Dim objItems As Items
Dim objItem As Object

Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")
Set objFolder = objNS.PickFolder
If Not objFolder Is Nothing Then
Set objItems = objFolder.Items
For Each objItem In objItems
' make sure you have a Contact item
If objItem.Class = olContact Then
' convert to your published custom form
objItem.MessageClass = "IPM.Contact.ContactsNewTwo"
' copy data to your custom fields
objItem.UserProperties("Billing Information") = objItem.User1
objItem.UserProperties("Custom2") = objItem.User2
objItem.UserProperties("Custom3") = objItem.User3
objItem.UserProperties("Custom4") = objItem.User4
objItem.User1 = ""
objItem.User2 = ""
objItem.User3 = ""
objItem.User4 = ""
objItem.Save
End If
Next
End If

Set objItems = Nothing
Set objItem = Nothing
Set objFolder = Nothing
Set objNS = Nothing
Set objApp = Nothing
End Sub
 
K

Ken Slovak - [MVP - Outlook]

BillingInformation is not a user property. Look at the object browser, it's
a standard property.

objItem.BillingInformation = objItem.User1
 
S

SLP

Thank you but after I changed it and tried to import, the import goes to the
default form. Any other ideas on what is wrong with the code? Outlook VBA
is new to me.
 
S

SLP

I just ran the code and this is where I am being told I have an error

Set objFolder = objNS.ContactsNew

The folder is called ContactsNew so I am not sure what I am doing wrong.
 
K

Ken Slovak - [MVP - Outlook]

You should learn to use the object browser. There is no property of the
NameSpace object called ContactsNew.

What you probably should be using is Set objFolder =
objNS.Folders("ContactsNew"), but that's only if the folder is at the same
level as your Contacts and Inbox folders. If it's a subfolder of other
folders then you need to address the folders that way, for example:

Set objFolder =
objNS.GetDefaultFolder(olFolderContacts).Folders("ContactsNew")

if the folder is a subfolder of your Contacts folder.
 
S

SLP

Thanks. I am new to Outlook VBA so any reference book you can suggest would
be appreciated.
 
K

Ken Slovak - [MVP - Outlook]

I'd look at the books listed at www.outlookcode.com, for beginners I'd
recommend Sue Mosher's books. That Web site is also the best resource for
Outlook coding information and code samples.
 

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