I’m working on a database that has a main document and several types of response documents. I have a button in a view. When a user clicks the button it should look to see if there is already a response document. If so, it should open that one. If one doesn’t exist, it creates a new one. This works fine. However, I’m having problems when I edit a response document. Here are the steps I’m doing when I see the problem:
-
Create a main document.
-
Click the button in the view to create a response document.
-
Enter some info in the response document and save and close it.
-
Use the same button again to bring up the response document and make changes to it.
-
Use the button again to bring up the response document.
When I do step 5, it brings up a previous version of the response document that doesn’t include the changes I made in step 4. If I open the document normally by double-clicking it, the changes are there. If I look at the document properties, my changes are there. If I close out of the database, re-open it and use the button, the changes are there. If I switch views and go back, my changes are there. Why aren’t they there when I do step 5 right away? I’m running into problems with save conflict messages because it’s not opening the document as it currently exists in the database.
I thought it might be a caching issue with shared actions, so I moved the code to a regular action button in the view, but it does the same thing.
What is going on? Here’s my code. Any ideas are welcome! Thanks!
Const THISFORM = “frmSched2”
Dim ws As NotesUIWorkspace
Dim parentDoc As NotesDocument, childDoc As NotesDocument
Dim session As NotesSession
Dim db As NotesDatabase
Dim coll As NotesDocumentCollection, childColl As NotesDocumentCollection
Dim formNm As String
Dim formFound As Boolean
Const FLD_FORM = “Form”
Sub Click(Source As Button)
'If a sched2 already exists, open that, otherwise create a new one
'if running from view, need to get the currently selected document
'if running from within a doc, need to get details from uidoc
Set ws = New NotesUIWorkspace
Set session = New NotesSession
Set db = session.CurrentDatabase
Set coll = db.UnprocessedDocuments
If coll.Count = 0 Then 'must be running from within doc, not from view
'running from within document
Set ws = New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Set uidoc = ws.CurrentDocument
If uidoc.IsNewDoc Then 'if this is a new document they need to save it first
Msgbox "You must save this main CE before you can create the attached schedules.",0+16,"Action Cancelled"
Exit Sub
End If
Set parentDoc = uidoc.Document
Call uidoc.Close
Else
'running from the view
Set parentDoc = coll.GetFirstDocument
End If
'We now have the backend parent document. Look for an existing sched2.
'If one exists open it. If not, create one and set it to be a response
'Find all the children and look for the form name
Set childColl = parentDoc.Responses
If childColl Is Nothing Then
'there are no responses, just create a new one
createNewResp
Exit Sub
End If
Set childDoc = childColl.GetFirstDocument
If childDoc Is Nothing Then
'there are no responses, just create a new one
createNewResp
Exit Sub
End If
While Not childDoc Is Nothing
'get the form name, if it's a sched2, open it in edit mode,
'if not sched2, get the next
formNm = childDoc.GetItemValue(FLD_FORM)(0)
If formNm = THISFORM Then
'open it in edit mode
formFound = True
Call ws.EditDocument(True,childDoc)
Exit Sub
Else
'do nothing, just get the next one to check
End If
Set childDoc = childColl.GetNextDocument(childDoc)
Wend
If formFound <> True Then
'no response of the correct type was found so create a new one
createNewResp
End If
End Sub
Sub createNewResp
Dim newResp As NotesDocument
Set newResp = db.CreateDocument
Call newResp.ReplaceItemValue(FLD_FORM,THISFORM)
Call newResp.MakeResponse(parentDoc)
'now open it for editing
Call ws.EditDocument(True,newResp)
End Sub