[Solved] Create a userfield if not excisting yet
Posted: Tue Feb 19, 2008 4:34 pm
Hello,
I am currently creating a LotusScript for Lotus Notes to automaticly generate documents.
LotusScript is based on VB. I am new to both LotusScript as VB so I might have made some mistakes.
I want to add values to userfields if they excist, if they don't then it should be created and this should be filled.
the problem is creating the new field, I found some java samples where a property value is needed to create the new field,
I thought this should be the way to do this.
Thanks in advance, Stijn.
I am currently creating a LotusScript for Lotus Notes to automaticly generate documents.
LotusScript is based on VB. I am new to both LotusScript as VB so I might have made some mistakes.
I want to add values to userfields if they excist, if they don't then it should be created and this should be filled.
the problem is creating the new field, I found some java samples where a property value is needed to create the new field,
I thought this should be the way to do this.
Thanks in advance, Stijn.
Code: Select all
'-----------------------------------------------------------------------------------
'--- FUNCTION: AddDocumentField
'--- DESCRIPTION: Fills the field or adds the field if not available.
'--- Reflection: "com.sun.star.reflection.CoreReflection"
'-----------------------------------------------------------------------------------
Function AddDocumentField(strName As String, strValue As String, oFields, Reflection)
On Error Goto ErrorHandler
onExit:
Dim field
Set field = oFields.getByName("com.sun.star.text.FieldMaster.User."+strName)
If Not field Is Nothing Then
Call field.setPropertyValue("Content", strValue)
End If
Exit Function
ErrorHandler:
Dim args(0)
Set args(0) = createPropertyStruct("com.sun.star.text.FieldMaster.User", Reflection)
args(0).Name = strName
args(0).Value = strValue
oFields.attachTextFieldMaster(args)
Resume onExit
EndErrorHandler:
End Function
'---------------------------------------------------------------------------------------------------------------------
'--- FUNCTION: createPropertyStruct
'--- DESCRIPTION: Create a property which can being added to the OOo / Symphony document.
'---------------------------------------------------------------------------------------------------------------------
Function createPropertyStruct(strTypeName As String, objCoreReflection As Variant) As Variant
Dim classSize As Variant
Print strTypeName
Set classSize = objCoreReflection.forName(strTypeName) 'This object is not been made and results in Nothing.
Dim aStruct
classSize.createObject aStruct 'because classSize is nothing an error shows.
Set createPropertyStruct = aStruct
End Function