Closing and opening document through button with Lotusscript

Hi

I have a document with a button on it. Pushing the button will perform certain actions.

One of them is closing the document and then open it again.

To do this i use this simple code

Set uidoc = ws.currentdocument

… other code…

call uidoc.Close(true)

Strange thing is that the last line does not close the document.

I cannot find out why that is. Does anyone has any idea?

Regards

Subject: Closing and opening document through button with Lotusscript

Hi,

Do You have any code in QueryClose event?

Konrad

Subject: Closing and opening document through button with Lotusscript

Pretty sure you’re going to need to move your code out to an agent so the button push shifts focus away from the current document. You can modify the code below to suit your needs. Put it in an Agent with Target = None, then call it from your button:

Option Public

Option Declare

Sub Initialize

%REM

AGENT : Close & Re-Open

PURPOSE: 

 -  Will close and re-open the current document so any background changes made to RichTextItems will be visible to the user without

 	 needing to save the document first.  This also allows Computed Subforms to be re-evaluated, and pass-thru HTML to be 

 	 re-loaded/calculated.

-  This code will trigger the QueryClose, QueryOpen & PostOpen events to run, but NOT the QuerySave event.



 	- From: http://www-10.lotus.com/ldd/nd6forum.nsf/55c38d716d632d9b8525689b005ba1c0/dd507a5be7cc2e4285256eec005f56ef?OpenDocument

 		with slight modifications	 	

%END REM

Dim s As New NotesSession

Dim ws As New NotesUIWorkspace

Dim db As NotesDatabase 

Dim uidoc As NotesUIDocument	

Dim newUIDoc As NotesUIDocument 

Dim thisDoc As NotesDocument

Dim newDoc As NotesDocument 

Dim currFieldname As String 

Dim errString As String 



On Error GoTo HANDLE_ERROR



Set db = s.CurrentDatabase	

Set uidoc = ws.CurrentDocument

currFieldname = uidoc.CurrentField 

' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

'	 *NOTE*   This is a kludge to get around the "Error #4412: Only plain text can be used in this type of field" that occurs ONLY if you use <Esc> to close a document

'					you've been editing.  If you use the [Save & Close] button the error doesn't seem to happen.   The kludge posted on the IBM 6&7 Forum is to put the 

'					cursor into a RichText field prior to doing the Source.Refresh(True).  It's the "True" parameter that throws the error.  This kludge seems to work, so we'll use it.

'

'					What Notes seems to do if you use the <Esc> key is put an Esc or some mysterious character into a field (I think the RichText one) & that causes

'					Notes to throw the error.

' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  	

Call uidoc.GotoField("Attachments")    ' this is a RichText field 

Call uidoc.Refresh(True)	' force any validation formulas to execute & update the RTItems ...

Set thisDoc = uidoc.Document



Call thisDoc.ComputeWithForm(False,False)

thisDoc.SaveOptions = "0"

’ Call uidoc.Close(True) ’ this causes an abend error 4419, incorrect argument type, object expected, so do not use

Call uidoc.Close

Set newUIDoc = ws.EditDocument(True,thisDoc)

Delete uidoc

newUIDoc.Document.RemoveItem("SaveOptions")

If currFieldname <> "" Then 

	newUIDoc.GotoField(currFieldname)

else

	newUIDoc.GotoField("StatusNotes")

End If 	

END_ROUTINE:

Exit Sub

HANDLE_ERROR:

errString = "Close & Re-Open -- Error #" + Format$(Err) + " on line " + Format$(Erl) + " : " + Error$  

MsgBox errString, 0+16+0+0, "An Error Has Occurred ..."

Resume END_ROUTINE

End Sub