LS button - won't close open document

Have created this button on a form to create new copy of this document cancelling out hours requested for vacation, etc. Does exactly what I need, BUT … the current open document won’t close … AND … new document(doc 2)save doesn’t go into the QuerySave and QueryClose events on the form which reset some fields, then go to a mail/review routine

Here is the complete code (with the offending Call doc.close remarked out). Any help would be appreciated. Just spent 5 hours here trying to find a similiar post!

Sub Click(Source As Button)

'Action to copy current document reversing the hours requested entries,

'submitting to supervisor, and effectively cancelling request

Dim session As New NotesSession	

Dim db As NotesDatabase

Dim workspace As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Dim doc As NotesDocument

Dim doc2 As NotesDocument

Set db = session.CurrentDatabase

'Get document, copy, change fields, then leave in Edit mode so staff can review and submit or CANCEL

Set uidoc = workspace.CurrentDocument

Set doc = uidoc.Document

Set doc2 = New NotesDocument (db)

’ doc2.SaveMessageOnSend = True

Call doc.CopyAllItems (doc2, True )

'Set fields to new values

Dim sick,ppd,ipp,vac,hol,per As Variant

Dim negate As Integer	

negate = (-1)

sick=negate * doc2.SickDays(0)

ppd = negate * doc2.PPDdays(0)

ipp = negate * doc2.IPPdays(0)

vac= negate * doc2.VacDays(0)

hol = negate * doc2.HolidayDays(0)

per = negate * doc2.PersonalDays(0)

oth= negate * doc2.OtherDays(0)

Set notesItem = doc2.ReplaceItemValue("SickDays", sick)

Set notesItem = doc2.ReplaceItemValue("PPDdays", ppd)

Set notesItem = doc2.ReplaceItemValue("IPPdays", ipp)

Set notesItem = doc2.ReplaceItemValue("VacDays", vac)

Set notesItem = doc2.ReplaceItemValue("HolidayDays", hol)

Set notesItem = doc2.ReplaceItemValue("PersonalDays", per)

Set notesItem = doc2.ReplaceItemValue("OtherDays", per)

Set notesItem = doc2.ReplaceItemValue("Form", "Cancel")

Set notesItem = doc2.ReplaceItemValue("Approved", "")	

Set notesItem = doc2.ReplaceItemValue("submitted", 1)

Set notesItem = doc2.ReplaceItemValue("NSubmitNOW", 1)

Set notesItem = doc2.ReplaceItemValue("Status", 2)

Messagebox  ("If approved by your supervisor, this request will be cancelled. It will still appear in your records, but the hours will be added back to your total.")

Call doc2.Save (False, False,True)					'Save new doc

Call doc.Save	(False, False, True)	

’ Call doc.Close([True])

Call workspace.ViewRefresh

End Sub

Subject: LS button - won’t close open document

The Close method applies to the Notesuidocument, not the Notesdocument:

Call uidoc.close(true)

Also, the Save method does not trigger the QuerySave/Close events. Put the code which resets the fields and runs the mail/review process into a script library - then you don’t have to duplicate the code and you can call it from your QuerySave/Close and from your button.

Subject: RE: LS button - won’t close open document

Good idea about the QuerySave/Close events. I’ll try it.

BUT - doc is a uidoc, isn’t it? Or is this where I’m going wrong. I know it seems dumb to do this, but uidoc.CopyAllItems won’t work but doing it this way does.

see:

Dim uidoc As NotesUIDocument

Dim doc As NotesDocument

Dim doc2 As NotesDocument

	

Set uidoc = workspace.CurrentDocument

Set doc = uidoc.Document

Subject: Try this…

Call doc2.Save (False, False,True)					'Save new doc	Call uidoc.Save

Call uidoc.Close(True)

Call workspace.ViewRefresh

Subject: Had to remark out one line - but it is closing now - THANKS!

Getting document command is not available on your code

getting the error on the Call uidoc.save line - remarked out one at a time

This is saving and closing the current open document as I needed:

Call doc2.Save (False, False,True) 'Save new doc

’ Call uidoc.Save

Call uidoc.Close(True)

Call workspace.ViewRefresh 	

Thanks so much - maybe my headache will be gone by the time I get home!

Subject: Complete correct code

I think the problem was that I couldn’t save the uidoc because I had opened it in Read-only mode. Hope this can help someone else!

This code takes the current open document, copies it to a new document, sets all of the hours fields to minus whatever is in the field, then saves the new doc and closes the open doc.

Sub Click(Source As Button)

'Action to copy current document reversing the hours requested entries,

'submitting to supervisor, and effectively cancelling request

Dim session As New NotesSession	

Dim db As NotesDatabase

Dim workspace As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Dim doc As NotesDocument

Dim doc2 As NotesDocument

Set db = session.CurrentDatabase

'Get document, copy, change fields, then leave in Edit mode so staff can review and submit or CANCEL

Set uidoc = workspace.CurrentDocument

Set doc = uidoc.Document

Set doc2 = New NotesDocument (db)

’ doc2.SaveMessageOnSend = True

Call doc.CopyAllItems (doc2, True )

'Set fields to new values

Dim sick,ppd,ipp,vac,hol,per As Variant

Dim negate As Integer	

negate = (-1)

sick=negate * doc2.SickDays(0)

ppd = negate * doc2.PPDdays(0)

ipp = negate * doc2.IPPdays(0)

vac= negate * doc2.VacDays(0)

hol = negate * doc2.HolidayDays(0)

per = negate * doc2.PersonalDays(0)

oth= negate * doc2.OtherDays(0)

Set notesItem = doc2.ReplaceItemValue("SickDays", sick)

Set notesItem = doc2.ReplaceItemValue("PPDdays", ppd)

Set notesItem = doc2.ReplaceItemValue("IPPdays", ipp)

Set notesItem = doc2.ReplaceItemValue("VacDays", vac)

Set notesItem = doc2.ReplaceItemValue("HolidayDays", hol)

Set notesItem = doc2.ReplaceItemValue("PersonalDays", per)

Set notesItem = doc2.ReplaceItemValue("OtherDays", per)

Set notesItem = doc2.ReplaceItemValue("Form", "Cancel")

Set notesItem = doc2.ReplaceItemValue("Approved", "")	

Set notesItem = doc2.ReplaceItemValue("submitted", 1)

Set notesItem = doc2.ReplaceItemValue("NSubmitNOW", 1)

Set notesItem = doc2.ReplaceItemValue("Status", 2)

Messagebox  ("If approved by your supervisor, this request will be cancelled. It will still appear in your records, but the hours will be added back to your total.")

Call doc2.Save (False, False,True) 'Save new doc

Call uidoc.Close(True)

Call workspace.ViewRefresh 	

End Sub

Subject: LS button - won’t close open document

First thought: you should never have this much code in a button. It should be stored in a script library or an agent that is called by the button.

Second thought:

You can do this in the QuerySave or PostSave event using script libraries.