Compose Document with Lotuscript

I have the following code in the ONCHANGE event for the field called PrepContract. PrepContract is a COMBOBOX field where a user can choose YES or NO. If the user chooses YES, then I want to compose a new document. If the user chooses NO, then I don’t want nothing to happen.

Sub Onblur(Source As Field)

  Dim ws As New notesuiworkspace

  Dim uidoc As notesuidocument

  Dim PrepContract As Variant

  If PrepContract = Yes Then	

  Set uidoc = ws.composedocument("","","Supply Contract")

Else

ArkemaPrepContract="No"

End If

End Sub

Can anyone provide assistance on how to get this working correctly?

Subject: Compose Document with Lotuscript

Try This:

1> Make sure your field type is a combobox.

2> Select Run Exiting/OnChange events after value change

3> Put the code in the ‘Exiting’ event not the onBlur event.

Shawn

Sub Exiting(Source As Field)

Dim session As New NotesSession

Dim ws As New NotesUIWorkspace

Dim db As New NotesDatabase("", "")

Dim scDocument As New NotesDocument(db)



scDocument.form = "Supply Contract"

Call scDocument.Save(False, False)

Call ws.EditDocument(True, scDocument)

End Sub

Subject: RE: Compose Document with Lotuscript

After implementing your code, I receive the following error message:

“Database has not been opened yet.”

Subject: Compose Document with Lotuscript

Dim ws As New notesuiworkspaceDim uidoc As notesuidocument

Dim uidocNew as NotesUIDocument

Dim doc as NotesDocument

Set uidoc = ws.CurrentDocument

Set doc = uidoc.Document

If doc.PrepContract(0) = “Yes” Then

Set uidocNew = ws.composedocument(“”,“”,“Supply Contract”)

Else

doc.ArkemaPrepContract=“No”

Call uidoc.Refresh '(optional)

Call uidoc.Save '(optional) or you could call doc.Save(False, True)

End If

This is just an example based on assumptions I’m making about what you’re trying to do. Also, I think that the OnBlur event is triggered when you actually exit the field (as opposed to just changing the Combo box selection).

Subject: RE: Compose Document with Lotuscript

Thank you very much for your help.Your code works perfectly. However, I do have one small problem. The new document being created does not create until I exit the field. I need the new document to be composed immediately when the field value is set to “Yes”.

I welcome your comments.

Subject: RE: Compose Document with Lotuscript

Bryant,

Did you complete step 2 from my previous post?

http://www-10.lotus.com/ldd/nd6forum.nsf/ShowMyTopicsAllFlatweb/1eff8887dce10ff78525738c00749fa6?OpenDocument

Shawn

Subject: RE: Compose Document with Lotuscript

Thank you for your help Shawn. I was able to get it to work.

Subject: RE: Compose Document with Lotuscript

Great!

Shawn