checking empty CustomDocumentProperties in MS Word

I am trying to edit the CustomDocumentProperties in MS Word. I have custom properties with a name and value already in CustomDocumentProperties, however, i want to check for an empty value under the 'Name' section. Looking at the code below, i am creating the actDoc.CustomDocumentProperties and checking that there are properties in there before i enter the If statements.


Dim objProps As Object

        Try
            objProps = actDoc.CustomDocumentProperties



            'covers empty properties
            'if property values are present in word document, do the following...
            If objProps.Count > 0 Then

'If the first property in CustomDocumentProperties exists, this first block of code is passed


                'if name doesn't exist, nor will value, so add both values
                If IsNothing(objProps.Item("EventTitle")) Then
                    objProps.Add(Name:="EventTitle", Value:=strTitle) ' Type:=Office.MsoDocProperties.msoPropertyTypeString, LinkToContent:=False,
                    'elseif name exists and value doesn't
                ElseIf Not IsNothing(objProps.Item("EventTitle").Name) And IsNothing(objProps.Item("EventTitle").Value) Then
                    objProps.Item("EventTitle").Value = strTitle
                Else
                    'both exist so do nothing
                End If

'however, if i have no more properties then the first If statment should be working, and adding the corresponding property values into CustomDocumentProperties, but
'this line of code is skipped and a "false parameter" error appears. I know the reason for this error is because it is checking for "PlantName" as the property name inside
'CustomDocumentProperties, which doesn't exist.


                If IsNothing(objProps.Item("PlantName")) Then
                    objProps.Add(Name:="PlantName", Value:=strPlant)
                ElseIf Not IsNothing(objProps.Item("PlantName").Name) And IsNothing(objProps.Item("PlantName").Value) Then
                    objProps.Item("PlantName").Value = strPlant
                Else
                End If


How do i check for a null property existence using only the built in methods of my objProps Object?
dev-ngps7Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

wguerramCommented:
Write this code between a Try - Catch

Try
   'If this code fails, it means PlantName is Null
   dim strTest as Object
   strTest = objProps.Item("PlantName").Value
catch
   'If an error occurs PlantName will be added
   objProps.Add(Name:="PlantName", Value:=strPlant)
end try

If  IsNothing(objProps.Item("PlantName").Value) Then
   objProps.Item("PlantName").Value = strPlant
End If
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.