Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

checking empty CustomDocumentProperties in MS Word

Posted on 2004-10-27
1
Medium Priority
?
700 Views
Last Modified: 2008-02-01
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?
0
Comment
Question by:dev-ngps7
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 8

Accepted Solution

by:
wguerram earned 2000 total points
ID: 12428848
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

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question