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*
On Error Resume Next: Set oPropSet3 = oPropSet("Operation 1 Setup Time 1"): On Error Goto 0and then testing forNothingto see if the property was found.If oPropSet3 Is Nothing Then. However, even if you get past that line,oPropSet3.Value = ""will fail because the object is Nothing.