Help with VBA code - Please!

R

Rafael

I have a custom contact form with the following custom field: Company Size
The textbox name and the field name are the same. I changed the new version
of the form so that the textbox "Company Size" is now linked to field
"User1".
Of course the company size data is now hidden and I'm having problems
accessing the data in "Company Size" and copying it to the new field.
So in short, two fields now share the same textbox name. How can I access
the original company size field and retrieve the data in it?

The code below is what I'm using to try and copy the data from the old field
to the new one.

For x = 1 To myOlSel.Count
Set myContact = myOlSel.Item(x)
myContact.User1 = myContact.UserProperties.Find("Company Size").Value
myContact.Save
Next x

The error I get on the third line is: Object variable or with block not set


Thanks,

Rafael
 
S

Sue Mosher [MVP-Outlook]

Sounds like your new form does not have the Company Size field defined in
the form. That means the field will not be present on the item unless that
property already contains data. If that's the case, since you apparently are
just doing a one-time update, you can put in an On Error Resume Next
statement and just ignore the error.

A more elegant solution would test for the property first:

Set objProp = myContact.UserProperties.Find("Company Size")
If Not objProp Is Nothing Then
myContact.User1 = objProp.Value
End IF
 
R

Rafael

Thanks Sue but I am sure the contact that I selected has data in the Company
Size field and yet I get the type mismatch error at the line indicated with
the comments below.

For x = 1 To myOlSel.Count
Set myContact = myOlSel.Item(x)
Set objProp = myContact.UserProperties.Find("Company Size")
If Not objProp Is Nothing Then
myContact.User1 = objProp.Value 'Error Type Mismatch occurs here
End If
myContact.Save

Thanks,

Rafael
 
R

Rafael

Sue - All,

Never mind. I rolled back to the old form. I need to do the reverse for
two folders now and that code is working just fine.

Thanks,

Rafael
 
S

Sue Mosher [MVP-Outlook]

Type Mismatch is a different error. How are you declaring MyContact and
objProp?
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
R

Rafael

I left those vars undeclared. I decided to go back one version so I don't
need this code working any longer.

Thanks for the effort.

Rafael
 

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