More Visual Basic/COM issues

I am trying to create a new memo using COM from Visual Basic (is this groundhog day?).Anyway, it’s OK I can access the mailfile.

And I can create a new document.

And I can set the Subject, and Save the document.

However, I can’t access the Body field.

And, when I open the document, the Body field is not there in the document properties until I save the document in the UI (perhaps LotusScript backend has the same issue).

Of course I need to use all BackEnd because UI is not supported in COM…

Here is some code, any ideas? Cheers.

'Do lots of other things related to Excel

'Then Declare some Domino Objects

Dim domSession As Object

Set domSession = CreateObject(“Lotus.NotesSession”)

Dim domDatabase As Object

Dim domDocument As Object

Dim domViewEntry As Object

Dim domView As Object

Dim domViewNav As Object

Dim domUIDocument As Object

Dim strName As String

Dim DesignField As NOTESRICHTEXTITEM 'Variant 'Object

Dim sEffortField

'Intialize the session

domSession.Initialize

'Get the users mailfile

Dim dir As Object

Set dir = domSession.GETDBDIRECTORY(“”)

Set domDatabase = dir.OpenMailDatabase

'Create a memo and save it

Set domDocument = domDatabase.CREATEDOCUMENT

Call domDocument.Save(True, True)

Call domDocument.REPLACEITEMVALUE(“Subject”, TitleAsText)

Call domDocument.Save(True, True)

Set DesignField = domDocument.GETFIRSTITEM(“Body”)

'domDocument.Subject = “New building”

Call domDocument.Save(True, True, True)

====

If I add a watch, the DesignField is set to Nothing here:

Set DesignField = domDocument.GETFIRSTITEM(“Body”)

And then later in the code I get an error trying to access it:

Call DesignField.APPENDSTYLE(richStyle)

Run Time error 91, Object variable or With block variable not set.

I am supposing this error is because DesignField is set to Nothing, but should be set to something, and I am supposing that is because the field is not accessible until the document is saved in the UI?

Does someone have an idea?

Subject: You need to use ComputeWithForm

To GND,Read the ComputeWithForm in the Notes Designer Help.

Add this line to the code to resolve:

Call domDocument.COMPUTEWITHFORM(False, False)

Subject: Didn’t work - more notes items are there but not the body field

Subject: Missing Body field

In your original code, use the CreateRichTextItem method of the NotesDocument class to create a Body field.

Subject: It works but…

Hi Chris,Yes, it works if you ‘CreateRichText item’.

To aid my understanding though:

  • Why do I need to ‘CreateRichText item’ ?

  • e.g. there is always a Body field on the emails I create ? Why do I need to create another field ? The Body field exists as a field on the Memo form already…

Subject: Because you are creating it via the backend

There is a world of difference between creating a document via LotusScript and via the user interface. When you create a document via LotusScript you get only the fields you specify (plus a couple of internal fields). When you create a document via the user interface, you get the fields defined in the form you use (plus its subforms etc). This is easy enough to see. Create an agent like the following in your mail file and run it. Then go to the All Documents view and look at the document properties using File, Properties i.e. without opening the document.

Dim session As New NotesSession

Dim db As NotesDatabase

Dim doc As NotesDocument



Set db = session.CurrentDatabase

Set doc = db.CreateDocument

doc.Subject = "AAA Test"

Call doc.Save(True, True)

Msgbox "Done"

You will see a document with probably just three fields: $TUA, $UpdatedBy and Subject. No Form field, no Body field etc, because you didn’t specify them in your code. Now open the document and save as draft then examine the document properties again. So unless you do that, or simulate doing that by using ComputeWithForm, you are not going to see all the extra fields.