VBA用户表单列表框双击事件

问题描述 投票:0回答:2

我有一个带有列表框的用户窗体,其中显示了表中的所有项目。列表框具有双击事件,其中;如果双击的行包含文本,则会打开一个编辑表单。如果双击的行为空,则会显示一个消息框,指出“该项目对编辑无效。”

我正在为此添加新功能,如果该行中的某个单元格包含“已关闭”,则会显示一个消息框,指出“此项目已关闭并且对编辑无效。

我不太擅长VBA,非常感谢您可以提供的任何帮助。下面是我当前的代码。

Private Sub RiskLogReviewListBox_DblClick(ByVal Cancel As MSForms.ReturnBoolean)

'Checks if the selected row is empty and outputs a message box if it is
    If Len(Trim(RiskLogReviewListBox.List(RiskLogReviewListBox.ListIndex, 0))) = 0 Then _
        MsgBox "The selected item is empty and not a valid entry for editing"

'Checks if the selected row is closed and outputs a message box if it is
    If RiskLogReviewListBox.Column(11, 0) = "closed" Then _
        MsgBox "The selected item is closed and not a valid entry for editing"

'Checks if the selected row is populated
    If Len(Trim(RiskLogReviewListBox.List(RiskLogReviewListBox.ListIndex, 0))) > 0 Then

提前感谢:)

vba listbox userform
2个回答
0
投票

找到解决方案

Private Sub RiskLogReviewListBox_DblClick(ByVal Cancel As MSForms.ReturnBoolean)

Dim i As Long

'Checks if the selected row is empty and outputs a message box if it is
    If Len(Trim(RiskLogReviewListBox.List(RiskLogReviewListBox.ListIndex, 0))) = 0 Then _
        MsgBox "The selected item is empty and not a valid entry for editing"

'Checks if the selected row is closed and outputs a message box if it is
    If (RiskLogReviewListBox.List(RiskLogReviewListBox.ListIndex, 10)) = "closed" Then
        MsgBox "The selected item is closed and not a valid entry for editing"
            Exit Sub
    Else

'Checks if the selected row is populated
    If Len(Trim(RiskLogReviewListBox.List(RiskLogReviewListBox.ListIndex, 0))) > 0 Then

0
投票

替换

 If RiskLogReviewListBox.Column(11, 0) = "closed" Then _

If Instr(RiskLogReviewListBox.Column(11, 0), "closed") > 0 Then _

但是,在上述两种情况下,您的代码必须存在。因此,我也建议在消息后使用Exit Sub ...

© www.soinside.com 2019 - 2024. All rights reserved.