On Error Resume Next seems not work

On Error Resume Next seems not work

gustavo.cassel
Advocate Advocate
945 Views
4 Replies
Message 1 of 5

On Error Resume Next seems not work

gustavo.cassel
Advocate
Advocate

I'm trying to modify a custom property, and if it not exists, create and give the value.

 

Public Sub UpdateCustomiProperty()
Dim oDoc As Document: Set oDoc = ThisApplication.ActiveDocument
Dim customPropSet As PropertySet
Set customPropSet = oDoc.PropertySets.Item("User Defined Properties")

Dim prop As Property
On Error Resume Next
Set prop = customPropSet.Item("MP")

If Err.Number <> 0 Then
Call customPropSet.Add(12345, "MP")
Else
prop.Value = 12345
End If
End Sub

 

Can someone explain why isn't working?

0 Likes
Accepted solutions (1)
946 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

Code works OK for me.  Is the active document ReadOnly (like ContentCenter stuff, or not checked out from Vault, or something like that)?  Are you getting an error message?  If so, what does the error message say (on both tabs of the error message)?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 5

gustavo.cassel
Advocate
Advocate

Why isn't working for me. It gives me this error box:

gustavocassel_0-1649079577554.png

Says that the method .Item of the object PropertySet Failed.

0 Likes
Message 4 of 5

gustavo.cassel
Advocate
Advocate

I changed this:

gustavocassel_0-1649080458912.png

And it works now. But this config will ignore all error that may occur?

0 Likes
Message 5 of 5

WCrihfield
Mentor
Mentor
Accepted solution

That's the same option I use all the time ("Break on Unhandled Errors").  In a sense, when using the phrase "On Error Resume Next" you are starting the behavior of...from this point on, ignore all minor (non-fatal) errors, which is a way of 'handling' errors.  That behavior can be reset to normal by using the phrase "On Error GoTo 0" (that last character is a zero, not a letter).  That does not tell your code to go to the start line of the code, just resets the error handling back to normal (default).  After you have checked for an expected possible error, and have done something in response (alternative) to that action, because of the error, it is often common practice to clear any existing errors and reset error checking back to normal for the following code, so you have a better understanding of any further errors that there may be, and can 'handle' them similarly.

On Error Statement (VBA) 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes