0

I should start out with this is my first attempt at a vba user form.

I Have some simple code to fill a user form (pulling from Inventor Custom iProperties) the problem I am running into and made a false assumption (that if the property didn't exist it would be ignored) so now I get an error. oProSet1 & oProSet2 work perfectly (Those iProperties will always have a value) oProSet3 Throws an error, I am guessing because the "Setup Time" property doesn't exist & Isn't required (in this case). The code asterisks is my attempt and fail to use an if statement.

Private Sub CommandButton2_Click()

' Get the active document.
Dim oDoc As Document
Set oDoc = ThisApplication.ActiveDocument

' Get the custom property set.
Dim oPropSet As PropertySet
Set oPropSet = oDoc.PropertySets.Item( _
"Inventor User Defined Properties")

Dim oPropSet1 As Property
Set oPropSet1 = oPropSet("Operation 1 Work Center 1")

 ' Set the value of the property.
TextBox1.Value = oPropSet1.Value

Dim oPropSet2 As Property
Set oPropSet2 = oPropSet("Operation 1 Machine Code 1")

 ' Set the value of the property.
TextBox2.Value = oPropSet2.Value

*Dim oPropSet3 As Property
Set oPropSet3 = oPropSet("Operation 1 Setup Time 1")
If oPropSet3("Operation 1 Setup Time 1") Is Nothing Then
 ' Set the value of the property.
 oPropSet3.Value = ""
 Else TextBox3.Value = oPropSet3.Value*
5
  • Are you referring to the proprietary AutoDesk Inventor Custom iProperties? knowledge.autodesk.com/support/inventor-products/learn-explore/… Commented May 24, 2022 at 18:30
  • "now I get an error" - what error do you get and on which line specifically? You can try ignoring the error On Error Resume Next: Set oPropSet3 = oPropSet("Operation 1 Setup Time 1"): On Error Goto 0 and then testing for Nothing to see if the property was found. Commented May 24, 2022 at 18:33
  • 1
    This is the error: And debug highlights in Yellow Set oPropSet3 = oPropSet("Operation 1 Setup Time 1") Run-time error '-2147467259 (80004005)': Method 'Item' of object 'PropertySet' failed Commented May 24, 2022 at 18:46
  • The syntax looks a little strange to me. I would try If oPropSet3 Is Nothing Then. However, even if you get past that line, oPropSet3.Value = "" will fail because the object is Nothing. Commented May 24, 2022 at 18:59
  • 1
    Hi Tim Williams, Dim oPropSet3 As Property On Error Resume Next: Set oPropSet3 = oPropSet("Operation 1 Setup Time 1") ' Set the value of the property. TextBox3.Value = oPropSet3.Value On Error GoTo 0 Works Perfectly! Thank you! Brent Commented May 24, 2022 at 19:06

1 Answer 1

1

I would try like this:

Dim oPropSet3 As Property

On Error Resume Next   'ignore error if missing
Set oPropSet3 = oPropSet("Operation 1 Setup Time 1")
On Error Goto 0        'stop ignoring errors

If oPropSet3 Is Nothing Then
    Debug.Print "Property not found"
Else
    Debug.Print oPropSet3.Value 
End If
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.