PDA

View Full Version : [SOLVED:] CustomDocumentProperties Problem



icthus123
10-05-2007, 06:52 AM
Hi, I'm using the code below to test whether or not a Custom Document Properties Item exists or not.



Set objPropBoiler = Me.CustomDocumentProperties.Item("Boiler")
If objPropBoiler Is Nothing Then bolExistsBoiler = False


However, when the Item doesn't yet exist the error "Invalid procedure call or argument" is given.

What is the problem here? Is there another way I can test whether or not the item exists?

fionabolt
10-05-2007, 08:38 AM
Here's some code that'll do what you want:


Dim bExistsBoiler As Boolean
Dim prop As DocumentProperty
For Each prop In ActiveDocument.CustomDocumentProperties
If prop.Name = "Boiler" Then
bExistsBoiler = True
End If
Next prop

icthus123
10-05-2007, 08:58 AM
Here's some code that'll do what you want:

Dim bExistsBoiler As Boolean
Dim prop As DocumentProperty
For Each prop In ActiveDocument.CustomDocumentProperties
If prop.Name = "Boiler" Then
bExistsBoiler = True
End If
Next prop

Great, that tactic works very well! Thanks! I don't suppose you have any idea why the way I was using wasn't working?

matthewspatrick
10-05-2007, 11:03 AM
Great, that tactic works very well! Thanks! I don't suppose you have any idea why the way I was using wasn't working?

It didn't work because when you tried to pull an item that did not exist,
you caused an error.

Another approach:



On Error Resume Next
Set objPropBoiler = Me.CustomDocumentProperties.Item("Boiler")
bolExistsBoiler = (Err = 0)
On Error GoTo 0

fumei
10-05-2007, 11:17 AM
In other words, the error itself tells you that "Boiler" does not exist. You can not set an object to something that does not exist.

icthus123
10-09-2007, 06:19 AM
Right okay thanks guys! I think the way I'm doing it now is the best tactic then! :beerchug: