Reputation: 195
Before this I already asked in here but I still did not get it fixed. I try every possible way but still cannot fix the problem.
I will try to explain again. Basically I have list of document with status "Active". So my button is on "Batch" view. My button process start with check all documents in "Computer" view whether there is "Lock" status. If any document have "Lock" status then exit sub, else continue process. Process continue is first set batch no. Then create copy document in "Computer". Copy document will have status "Draft" and current document will replaceitemvalue to "Lock". This process will continue for all document.
So below here my lotusscript button.
Set db = session.CurrentDatabase
Set uiview = ws.CurrentView
Set uidoc = ws.CurrentDocument
Set dialogDoc = uidoc.Document
Set view = db.GetView("Computer")
Set doc = view.GetFirstDocument
While Not (doc Is Nothing)
If doc.PStatus(0) = "Lock" Then
Msgbox "Complete PC Inspection first!"
Exit Sub
Else
answer% = Messagebox("Do you confirm?")
If Not answer% = 6 Then
Msgbox("Process Incomplete")
Exit Sub
Else
dialogDoc.Form = "BatchInfo"
Call uidoc.FieldSetText("SaveOptions", "1")
Call uidoc.Save
While Not (doc Is Nothing)
If doc.PStatus(0) = "Active" Then
'-----create new copy document-----'
Set newdoc = doc.CopyToDatabase(db)
newdoc.PBatchNo = dialogDoc.BBatchNo(0)
newdoc.PStatus = "Draft"
Call newdoc.Save(True, False)
doc.PStatus = "Lock"
Call doc.ComputeWithForm(False,False)
Call doc.save(True,False)
End If
Set doc = view.GetNextDocument(doc)
Wend
Messagebox("Process completed.")
End If
End If
Exit Sub
Wend
So right now all documents in "Computer" will have status "Lock", so when I click again the button, it should straight exit sub.
First testing: So right now, I will change status of any document in "Computer" list from "Lock" become "Active". Any document except first document. Then I will return "Batch" view and CLICK button, it show msgbox "Complete PC Inspection first!". It means there is no problem
Second testing: So now, I try second testing. This testing is similar with first testing but for this testing, I will change status of document for very "First Document" in "Computer" view. Then I return back to "Batch" view and CLICK button, it ignore message and go to line 14 which is "answer% = Messagebox("Do you confirm?")". It not supposed to skip to this line because in "Computer" view, there are still document with "Lock" status.
I have try any possible way but I cannot succeed. Anyone can help with my problem? I really appreciate it. Thank you
Upvotes: 0
Views: 137
Reputation: 825
Judging from your description of what you are trying to do, I think you need toclose your first While..Wend loop before getting to your first Else
Set db = session.CurrentDatabase
Set uiview = ws.CurrentView
Set uidoc = ws.CurrentDocument
Set dialogDoc = uidoc.Document
Set view = db.GetView("Computer")
'First run through the loop checks if ANY doc has PStatus = "Lock"
Set doc = view.GetFirstDocument
While Not (doc Is Nothing)
If doc.PStatus(0) = "Lock" Then
Msgbox "Complete PC Inspection first!"
Exit Sub
End If
Set doc = view.getNextDocument(doc) 'add (doc)
Wend
'Not sure what this is all about, but I'll leave it in
answer% = Messagebox("Do you confirm?")
If Not answer% = 6
Msgbox("Process Incomplete")
Exit Sub
Else
'I've no idea what the next three lines are for, but I'll leave them alone
dialogDoc.Form = "BatchInfo"
Call uidoc.FieldSetText("SaveOptions", "1")
Call uidoc.Save
'Loop through the view again, creating copies and setting status to Lock
Set doc = view.GetFirstDocument 'Add this line
While Not (doc Is Nothing)
If doc.PStatus(0) = "Active" Then
'-----create new copy document-----'
Set newdoc = doc.CopyToDatabase(db)
newdoc.PBatchNo = dialogDoc.BBatchNo(0)
newdoc.PStatus = "Draft"
Call newdoc.Save(True, False)
doc.PStatus = "Lock"
Call doc.ComputeWithForm(False,False)
Call doc.save(True,False)
End If
Set doc = view.GetNextDocument(doc)
Wend
End If
Messagebox("Process completed.")
I hope that helps. I think your problem was the you thought you were going through the whole view looking for a document with PStatus = "Lock", but because your Wend was right at the end of the code, and there wasn't a view.getnextdocument(doc), it simply wasn't happening.
Upvotes: 1