Can get custom propertiesfrom new active doc, but not set them!

Hello all, I'm trying to set Custom properties from my custom macro.

I can get a Custom property , but when i try to set a custom property I have no working result.

I have looked in the API's for help and not found or undestand the answers/examples. After i have created teh Part document as rename and saved it

I want to copy some of the fields in the form and from varibles into the Custom properties. Or into the Custom Property Tab interface as an alternate.

Either way will work. the swCustProp.set2() method seem to always error out with runtime error 438 (Object doesn't support this property or method)

Am I missing something here?

Declarations

Option Explicit

'Define objects

Dim Part As Object

Dim rs As Object

Dim OpenConnection As Object

Dim objFields As Object

Dim swApp As sldworks.sldworks

Dim swModel As ModelDoc2

Dim swModelDocExt As ModelDocExtension

Dim swCustProp As Object 'CustomPropertyManager

Dim val1 As String

Dim PathName  As String

Dim Filepath  As String

Dim valout As String

Dim bool As Boolean

Dim partnumber As String

Dim boolstatus As Boolean

Dim longstatus As Long, longwarnings As Long

Here is my code snipet

    '************************************************************

    'Open a new design in solidworks and renames file and saves to working directory

    '************************************************************

Sub createnewpart()

'Dim instance As ICustomPropertyManager

Dim FieldName As String

Dim FieldValue As String

Dim valuert As Integer

        If UserForm1.DocTypeLabel.Caption = ".SLDASM" Then

        Set swModel = swApp.NewAssembly()

        End If

        If (UserForm1.DocTypeLabel.Caption = ".SLDPRT") Then

        Set swModel = swApp.NewPart()

        End If

        'If (UserForm1.DocTypeLabel.Caption = ".SLDDRW") Then Set swModel = swApp.NewDrawing

        Set swModelDocExt = swModel.Extension

        ' Get the custom property data

        FieldName = "PART_NUMBER"

        FieldValue = UserForm1.NewCategoryTextBox.Value + "-" + UserForm1.NewCatindexTextBox.Value

        'valuert = swCustProp.Add3(FieldName, swCustomInfoText, FieldValue, 2)

       

        'swCustProp.Set "PART_NUMBER" = newfilename1

        'swCustProp.Get2 "PART_NUMBER", val1, valout

        'PathName = "C:\PDM_working"

        'PathName = swModel.GetPathName     'this gets the full path of the current open document (including filename)

        Debug.Print "Path name = " + PathName, "File name= " + newfilename1

        Filepath = PathName + "\" 'uses to full pathname to get the folder path, to be added to the save as file name

        If (swModel.GetType = swDocASSEMBLY) Then

            swModel.SaveAs (Filepath + newfilename + ".sldasm")

        

        ElseIf (swModel.GetType = swDocPART) Then

             swModel.SaveAs (Filepath + UserForm1.NewCategoryTextBox.Value + "_" + UserForm1.NewCatindexTextBox.Value + ".sldprt")

        

        End If

       

        Set swModel = swApp.ActiveDoc

        Set swModelDocExt = swModel.Extension

        Set swCustProp = swModelDocExt.CustomPropertyManager("")

        swCustProp.Get2 "PART_NUMBER", val1, valout

        Debug.Print "VAL1= " + val1, "Valout = " + valout 'this works

        valuert = swCustProp.Set2(FieldName, newfilename1)  'this dosen't set the PART_NUMBER custom property!

End Sub

SolidworksApi macros