Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If MsgBox("是否要退出?", vbOKCancel, "提示") = vbOK Then
    Cancel = 0
Else
    Cancel = 1
End If
End SubPrivate Sub CmdExit_Click()
    Unload Me
End SubPrivate Sub CmdMsg_Click()
    Unload Me
    frmmain.Show
End Sub如何在CmdMsg_Click事件中中调用Form_QueryUnload事件下的判断语句

解决方案 »

  1.   

    写个函数或者直接调用
    Private Sub CmdMsg_Click()
        Form_QueryUnload
        ……
    End Sub
      

  2.   

    我是想调用msgbox
    选OK运行下一步
    NO返回,什么也不发生
      

  3.   

    不一样的,要加参数
    cancel An integer. Setting this argument to any value other than 0 stops the QueryUnload event in all loaded forms and stops the form and application from closing. unloadmode A value or constant indicating the cause of the QueryUnload event, as described in Return Values. 
    Return ValuesThe unloadmode argument returns the following values:Constant Value Description 
    vbFormControlMenu 0 The user chose the Close command from the Control menu on the form. 
    vbFormCode 1 The Unload statement is invoked from code. 
    vbAppWindows 2 The current Microsoft Windows operating environment session is ending. 
    vbAppTaskManager 3 The Microsoft Windows Task Manager is closing the application. 
    vbFormMDIForm 4 An MDI child form is closing because the MDI form is closing. 
    vbFormOwner 5 A form is closing because its owner is closing. 
      

  4.   

    不一样的,要加参数
    cancel An integer. Setting this argument to any value other than 0 stops the QueryUnload event in all loaded forms and stops the form and application from closing. unloadmode A value or constant indicating the cause of the QueryUnload event, as described in Return Values. 
    Return ValuesThe unloadmode argument returns the following values:Constant Value Description 
    vbFormControlMenu 0 The user chose the Close command from the Control menu on the form. 
    vbFormCode 1 The Unload statement is invoked from code. 
    vbAppWindows 2 The current Microsoft Windows operating environment session is ending. 
    vbAppTaskManager 3 The Microsoft Windows Task Manager is closing the application. 
    vbFormMDIForm 4 An MDI child form is closing because the MDI form is closing. 
    vbFormOwner 5 A form is closing because its owner is closing. 
      

  5.   

    If MsgBox("是否要退出?", vbOKCancel, "提示") = vbOK Then
        .......
    End If
      

  6.   

    Private Sub CmdMsg_Click()
        Unload Me
    End Sub这样就行了~~不用调用Form_QueryUnload啊!!
      

  7.   

    Private Sub CmdMsg_Click()
        Unload Me
    End Sub这样就行了~~不用调用Form_QueryUnload啊!!
      

  8.   

    是这样的,
    我在主窗体FrmMain中点击“更换用户“
    要先关闭主窗体,会弹出提示,选择“确定“
    关毕主窗体,打开登录窗口
    选择“取消“就返回主窗体
    问题是,在我点击“更换用户“后
    选择“取消“后不仅仅是返回主窗体,
    还会打开登录窗口
    为什么
      

  9.   

    if msgbox = vbok then
       unload me
       登录。show
    end if
      

  10.   

    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    If MsgBox("是否要退出?", vbOKCancel, "提示") = vbOK Then
        Cancel = 0
        登陆.show 
    Else
        Cancel = 1
    End If
    End SubPrivate Sub CmdMsg_Click()
        Unload Me
    End Sub写就行了
      

  11.   

    你的意思是 在CmdMsg_Click事件里调用 Unload Me 以后不执行 QueryUnload 事件的内容,而直接关闭窗口?
    对不起,我是猜的,如果不对请原谅。