Storing details in custom properties

Robie
5StarLounger
Posts: 656
Joined: 18 Feb 2010, 14:26

Storing details in custom properties

Post by Robie »

I have to store company details (name, addresses, telephones, etc) in the custom properties.

Is it possible to store paragraph mark/line feed characters in them?

The idea is that I would have three custom property fields, each containing name, addresses and telephone details. I am hoping to use this field as an array to extract the relevant company information based on the user selection and insert it in a document. Obvioulsy, the address will be 3/4 lines.

For example, custom property fields
CNAMES= ABCD ;EFGH; ;MNOP ;etc.
CADDRESSES=1 View Street,(line feed)Duke Lane,(line feed)Suffolk;27 North Priory,(line feed)London;12 the lane,(line feed)NY;etc.
CTELEPHONES=0893030303030303 ;039383773737373773 ;7487438743873487 ;etc.

Thanks.
Robie

Robie
5StarLounger
Posts: 656
Joined: 18 Feb 2010, 14:26

Re: Storing details in custom properties

Post by Robie »

Robie wrote:I have to store company details (name, addresses, telephones, etc) in the custom properties.

Is it possible to store paragraph mark/line feed characters in them?

The idea is that I would have three custom property fields, each containing name, addresses and telephone details. I am hoping to use this field as an array to extract the relevant company information based on the user selection and insert it in a document. Obvioulsy, the address will be 3/4 lines.

For example, custom property fields
CNAMES= ABCD ;EFGH; ;MNOP ;etc.
CADDRESSES=1 View Street,(line feed)Duke Lane,(line feed)Suffolk;27 North Priory,(line feed)London;12 the lane,(line feed)NY;etc.
CTELEPHONES=0893030303030303 ;039383773737373773 ;7487438743873487 ;etc.

Thanks.
Robie
The above may be confusing so how about this. We would have multiple of these name/address for each location for the compnay. The reason for doing this is that the user selects the location and it update the company information in the document - simple. The reason for having it in the custom properties field is that we can change the content if e.g. the telephone number changes for a particular location (i.e. we don't have to change the code in the template).

Store this in a custom property so that all we do is display the custom property as a field on the document.
19.png
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78629
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Storing details in custom properties

Post by HansV »

You can do so in VBA code:

Code: Select all

Sub SetProperty(strName As String, strValue As String)
    Dim prp As DocumentProperty
    On Error GoTo ErrHandler
    Set prp = ActiveDocument.CustomDocumentProperties(strName)
    prp.Value = strValue
    Exit Sub
ErrHandler:
    If Err = 5 Then
        Set prp = ActiveDocument.CustomDocumentProperties.Add _
            (Name:=strName, LinkToContent:=False, _
            Type:=msoPropertyTypeString, Value:="")
        Resume Next
    End If
End Sub

Sub Test()
    SetProperty "CADDRESSES", "1 View Street," & vbCrLf & "Duke Lane," & vbCrLf & "Suffolk"
End Sub
Best wishes,
Hans

Robie
5StarLounger
Posts: 656
Joined: 18 Feb 2010, 14:26

Re: Storing details in custom properties

Post by Robie »

HansV wrote:You can do so in VBA code:

Code: Select all

Sub SetProperty(strName As String, strValue As String)
    Dim prp As DocumentProperty
    On Error GoTo ErrHandler
    Set prp = ActiveDocument.CustomDocumentProperties(strName)
    prp.Value = strValue
    Exit Sub
ErrHandler:
    If Err = 5 Then
        Set prp = ActiveDocument.CustomDocumentProperties.Add _
            (Name:=strName, LinkToContent:=False, _
            Type:=msoPropertyTypeString, Value:="")
        Resume Next
    End If
End Sub

Sub Test()
    SetProperty "CADDRESSES", "1 View Street," & vbCrLf & "Duke Lane," & vbCrLf & "Suffolk"
End Sub

:clapping: :fanfare:
Thanks Hans, that is exactly what I wanted.