Link to home
Start Free TrialLog in
Avatar of Leif Borgman
Leif Borgman

asked on

Outlook 2010 VBA Object required Error

This is my first question here so bear with me. I have an Outlook/VBA issue that is driving me batty.
I have customized the Outlook Contact form and added a number of user defined fields and now I need to run a VBA routine to update 2 newly added custom fields.
Here's the relevant code:
    Set objExpl = Application.ActiveExplorer
    If Not objExpl Is Nothing Then
        Set objSelection = objExpl.Selection
        If objSelection.Count > 0 Then
            For i = 1 To objSelection.Count
                Set objItem = objSelection.item(i)
                If Not objItem Is Nothing Then
                    If objItem.Class = olContact Then
                        objItem.UserProperties("EmployerIndustry").Value = txtIndustry.Text

The user defined field "EmployerIndustry" gets the value from the textbox. When this line is executed, a message box is thrown up: Script Error Object required: '' Line No:74
And when I check the error number it shows nbr 91.

However, if I change the user defined property to another one, say "Newsletter" there's no error. Yesterday I called this property "MajorCategory" and it kept throwing this error, so I changed the field name to "EmployerIndustry" and then it worked. Today the same error is showing up again.

After the messagebox is dismissed the code functions as it should and the value gets set in the user defined field. If I add a Quickwatch and check the values, everything looks as it should.

If I open a contact item and check User-defined fields in this item and in this folder, the field is there.

I have other VBA routines that do various updates to User-defined properties and they all run without errors with the same code. I have seen some people suggest that I declare and initialize the UserProperties collection and then add the property and assign that to a variable and finally set the value from the text box to this variable, tried that, same result.

Can you shed some light on this? Would really, really appreciate it.

Leif
ASKER CERTIFIED SOLUTION
Avatar of Leif Borgman
Leif Borgman

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Seth Simmons
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Accept: Leif Borgman (https:#a42446054)

If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

seth2740
Experts-Exchange Cleanup Volunteer