Solved

Postopen code leaves document open twice

Posted on 2003-11-10
9
453 Views
Last Modified: 2013-12-18
This is a weird one for you.

I have a "report" form that collects and formats information from other documents in the database, dumping the results nicely into a rich-text field. The data collection is handled in the Postopen event, if the document is new.

Because the resulting field is rich-text, it does not show updates until the document is closed and reopened. So I have this code at the very end of all the rest of the stuff in the Postopen:

==== BEGIN PASTE ====
      Call Source.Document.Save(True, False)
      Source.Document.SaveOptions = "0"
      Call Source.close
      Call ws.ViewRefresh
      Set uidoc = ws.EditDocument(False, doc)
===== END PASTE =====

Note that doc, in this case, is a NotesDocument that is declared in the form's (Declarations) section (not the Globals (Declarations) section, and its value is set to Source.Document. Likewise, ws is the NotesUIWorkspace that is declared in the (Declarations) section and set as a New NotesUIWorkspace.

This is all fine -- half the time. I have two major classifications of reports that can be generated, based on the user's responses to some ws.Prompts in the PostOpen. For one classification of reports, I have no problems. For the other, when the process is complete the new report is on the screen, but there are two "task buttons" in the bar, indicating that the document is open twice. The first task button contains the calculated name of the re-opened report document, and the second contains the calculated name of a new report document. If you click on the two task buttons, you can go back and forth between the two documents: the one that shows the complete report, and the one that shows the document as it appeared before it was saved.

The two classifications of reports collect information from the same pool of documents, though they collect different information. The report format that exhibits this quirk uses an array of objects of a class declared in the form's (Declarations) section. The array is processed in a subroutine, where it declared dynamically. As the subroutine closes, it runs this code:

==== BEGIN PASTE ====
      For intCount = 1 To Ubound(detailLines)
            Set detailLines(intCount) = Nothing
      Next
      
      Redim detailLines(0 To 0)
      Set detailLines(0) = Nothing
      Set varDetailLines = Nothing
===== END PASTE =====

Obviously, detailLines() is the dynamic array of objects of my class. varDetailLines is another instance of the class.

The report format that doesn't exhibit this quirk does not use any variable type other than the standard Notes classes. I don't know that the class thing is causing my problems, but it is the chief significant difference between the processing of the two formats of report.

Does anyone have any idea how I can get that second "empty" document to not appear? It's all that much more baffling, given that the empty one appears after the "full" document in the Task Button bar. Even more so, when the report generation is complete, the "full" document is showing, though the "empty" task button appears to be selected.

Thanks for any help you can provide. I always like to come in with a good challenge for you!

-- b.r.t.
0
Comment
Question by:BarryTice
  • 2
  • 2
  • 2
  • +1
9 Comments
 
LVL 31

Expert Comment

by:qwaletee
ID: 9718732
Is it a single form that does blth classes of report, or different forms?
0
 
LVL 7

Author Comment

by:BarryTice
ID: 9718764
Same form, qwaletee. Whichever report is generated is dumped into a calculated rich-text field (called "Body", with a formula of Body). That way, when the report is viewed after creation, it's just showing the collected data.
-- b.r.t.
0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 9718882
Here is my suggestion

Create an agent which will collect all the data thru prompts and then Create empty report document with all necessary parameters collected into fields and save it and open the document. Then during QueryOpen using this script get backend handle of the document and then begin processing (you can also do this in agent and after dumping data open the document that is more easy)

Dim session as New NotesSession
Dim db as NotesDatabase
Dim doc as NotesDocument
set db = session.CurrentDatabase
set doc = db.GetDocumentByUNID( Source.Document.UniversalID )
' Here do reporting on the doc -- this will effectively open the report with complete data


~Hemanth
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 31

Expert Comment

by:qwaletee
ID: 9719343
Oh, c'mon, let's try fixing Varry's problem before completely reworking the code.
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 9720977
I think Hemanth does have a point here. If doc is set to Source.document, then doc should be Nothing after calling the Close method on Source. It could be that the Close is skipped, for whatever reason, since the form is in the PostOpen and therefore intrinsically open.

Possible solution: get an independent doc and use that one to open the form on the screen. Like the statement
   Set doc = db.GetDocumentByUNID( Source.Document.UniversalID )
0
 
LVL 7

Author Comment

by:BarryTice
ID: 9722214
OK, so I've changed the closing code to this:
==== BEGIN PASTE ====
      strID = doc.UniversalID
      Call Source.Document.Save(True, False)
      Source.Document.SaveOptions = "0"
      Call Source.close
      Call ws.ViewRefresh
      Set doc = db.GetDocumentByUNID(strID)
      Set uidoc = ws.EditDocument(False, doc)
===== END PASTE =====
with strID declared in the Postopen as a string.

No change. I'm still getting two open documents at the end.

In the absence of figuring out what's going on here, I expect I'll end up moving this to an agent. But I'd rather figure out what's going on.

-- b.r.t.
0
 
LVL 46

Accepted Solution

by:
Sjef Bosman earned 250 total points
ID: 9730509
Weird. But reopening documents for the sake of computed rich text fields has always been an tricky thing. I think it must be a timing issue. You could try to move your code to the QueryClose event, like this:

in Declarations:
Dim process_flag As Integer

in PostOpen:
If "proccessing is required" Then
   process_flag= True
   Call Source.Close
End If

in QueryClose:
If process_flag Then
   ' do_your_thing
End If

If you are going to rework your code, since I wonder why you want to open and reopen the document, you could just use a view button running on unprocessed documents.

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I thought it will be a good idea to make a post as it will help in case someone else faces these issues. I trust this gives an idea how each entry in Notes.ini can mean a lot for the Domino Server to be functioning properly. This article discusses t…
Article by: Rob
Notes 8.5 Archiving Steps and Tips This article covers setting up a Notes archive, and helps understand some of the menu choices making setting up and maintaining a Notes archive file easier.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now