我有一个包含合同详细信息的记录表单和一个子表单,我在其中输入了一些其他信息。主窗体有一个命令按钮来关闭它。
我需要在关闭时检查2个控件(一个在主窗体中,一个在子窗体中),如果满足某些条件,则应显示是/否MsgBox。如果用户按下“是”,表格将关闭,如果他按“否”,表格将保持打开状态。
到目前为止,我有这个:
Private Sub Form_Unload(Cancel As Integer)
Dim Response As Integer
Response = MsgBox("It looks like this contract is fixed. Would you like to edit the final price?", vbYesNo, "Database Information")
If Me![fixed price] = 0 And Me![Fixation Orders Subform1].Form!Text38 = "Final Fixed Price" Then
Cancel = True And Response
If Response = vbYes Then
Cancel = True
Else
Cancel = False
End If
Else
Cancel = False
End If
End Sub
问题:在我定义“响应”之前,MsgBox正确显示,但表单仍然关闭。在我定义它以在第二个“If”中使用它之后:
另外,在我解决这个问题之后,当我进入下一个记录时,我应该在哪个事件中使用此代码来查看条件?提前谢谢。
答案 0 :(得分:0)
我认为它应该是这样的:
Private Sub Form_Unload(Cancel As Integer)
If Me![fixed price] = 0 And Me![Fixation Orders Subform1].Form!Text38 = "Final Fixed Price" Then
If MsgBox("It looks like this contract is fixed. Would you like to edit the final price?", vbYesNo, "Database Information") = vbYes Then
Cancel = True
End If
End If
End Sub