RichText Field basic problem

Hi.I have a database Form which contains a RichText Field called ‘ChemFormula’.

I want to be able to extract the contents of this field, edit it, and apply different formatting to different parts of it.

I’m a beginner as far as RichText Fields are concerned, and I’m having difficulty just setting up a basic template to deal with this.

The code I’ve written below gives me the error ‘Object variable not set’ for the Call statement near the end.

Any help with this problem would be great.

Thanks.

Sub Click(Source As Button)

Dim ws As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Dim doc As NotesDocument



Dim session As New NotesSession 

Dim richStyle As NotesRichTextStyle



Dim molForm As Variant



Set uidoc = ws.CurrentDocument

Set doc = uidoc.Document



Set richStyle = session.CreateRichTextStyle

Set doc.ChemFormula = New NotesRichTextItem(doc, "Field")



richStyle.Effects= EFFECTS_SUBSCRIPT

Call doc.ChemFormula.AppendStyle(richStyle)



molForm = doc.getitemvalue("ChemFormula")(0)	



Msgbox "Molecular Formula = " & molForm

End Sub

Subject: RichText Field basic problem

you need to …

dim rtItem as notesRichTextItem

set rtItem = new NotesRichTextItem( doc, “field”)

call rtItem.appendStyle( richStyle)

I have no idea on what you are trying to do with chemformula.

John

Subject: RE: RichText Field basic problem

Thanks for your help, John.But I still can’t get it to work.

Just to re-cap in a bit more detail:

I have a form with a rich-text field on it call ‘ChemFormula’.

I want to pick up the contents of this field and put it in a variable called ‘molForm’.

I then want to change the string which molForm contains by adding some text to it which is subscripted.

Then I want to put the string which molForm contains back into the rich-text field call ‘ChemFormula’.

The code I have so far is shown below.

(The code doesn’t seem to do anything, so I’m obviously missing something.)

I am going about this the wrong way?

Sub Click(Source As Button)

Dim ws As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Dim doc As NotesDocument



Dim session As New NotesSession 

Dim richStyle As NotesRichTextStyle

Dim rtItem As NotesRichTextItem



Dim molForm As Variant



Set uidoc = ws.CurrentDocument

Set doc = uidoc.Document



Set richStyle = session.CreateRichTextStyle

Set rtItem = New NotesRichTextItem(doc, "Text")



molForm = doc.getitemvalue("ChemFormula")(0)



richStyle.Effects= EFFECTS_SUBSCRIPT

Call rtItem.AppendStyle(richStyle)

Call rtItem.AppendText(molForm)

Call rtItem.AppendText(" added text")



Msgbox ("Molecular Formula = " & molForm & Chr(10) & "rtItem = " & "Body")



Call doc.ChemFormula.AppendText(rtItem)



Call doc.Save(True,False)

End Sub

Subject: RE: RichText Field basic problem

Richard

You may be going the long way to get what you want. Does this do what you want?

Dim ws As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Dim doc As NotesDocument

Dim session As New NotesSession

Dim richStyle As NotesRichTextStyle

Dim rtItem As NotesRichTextItem



Set uidoc = ws.CurrentDocument

Set doc = uidoc.Document



Set richStyle = session.CreateRichTextStyle

Set rtItem = doc.getFirstItem( "ChemFormula")

richStyle.Effects= EFFECTS_SUBSCRIPT

Call rtItem.AppendStyle(richStyle)

Call rtItem.AppendText(" added text")

Msgbox "ChemFormula = " & rtItem.text

Call doc.Save(True,False)

Subject: RE: RichText Field basic problem

Thanks a lot for your help, John.The code is now working fine.

:slight_smile: