为什么我的表单按钮不能正常工作

Why is my button in form not worked properly

在此之前,我已经在here中询问过,但我仍然没有解决。各种办法都试过了还是没办法解决问题

我再试着解释一下。基本上我有状态为 "Active" 的文档列表。所以我的按钮在 "Batch" 视图上。我的按钮流程从检查 "Computer" 视图中的所有文档是否存在 "Lock" 状态开始。如果任何文档具有 "Lock" 状态,则退出 sub,否则继续处理。 Process continue 首先设置批号。然后在 "Computer" 中创建副本文档。复制文档的状态为 "Draft",当前文档会将项目值替换为 "Lock"。此过程将对所有文档继续。

下面是我的 lotusscript 按钮。

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

所以现在 "Computer" 中的所有文档都将具有状态 "Lock",所以当我再次单击该按钮时,它应该直接退出子。

第一次测试: 所以现在,我会将 "Computer" 列表中任何文档的状态从 "Lock" 更改为 "Active"。除第一个文档之外的任何文档。然后我将 return "Batch" 查看并点击按钮,它显示 msgbox "Complete PC Inspection first!"。表示没有问题

第二次测试: 所以现在,我尝试进行第二次测试。此测试与第一次测试类似,但对于此测试,我将在 "Computer" 视图中更改非常 "First Document" 的文档状态。然后我 return 返回 "Batch" 查看并单击按钮,它忽略消息并转到第 14 行 "answer% = Messagebox("Do you confirm?")"。它不应该跳到这一行,因为在 "Computer" 视图中,仍然有状态为 "Lock" 的文档。

我尝试了所有可能的方法,但我无法成功。任何人都可以帮助解决我的问题吗?我真的很感激。谢谢

从你对你想要做什么的描述来看,我认为你需要先关闭你的第一个 While..Wend 循环,然后再进入你的第一个 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.")

希望对您有所帮助。我认为你的问题是你认为你正在浏览整个视图来寻找 PStatus = "Lock" 的文档,但是因为你的 Wend 就在代码的末尾,并且没有 view.getnextdocument(doc),这根本就没有发生。