在同一个Sub中运行两个if语句

时间:2017-12-18 21:57:41

标签: vba ms-access access-vba

我一直在试图弄清楚如何在一个sub中运行两个If语句。这些If语句彼此完全不同。它们不是基于多种条件的一种行为。它们是影响两个按钮标签的两个动作。

If x > 0 Then
Me.isResolved.backcolor = "5921504"
Me.isResolved.Caption =  X & " Notes need reviewed."
       If Y > 0 Then
       Me.unfinished.backcolor = "5921504"
       Me.unfinished.Caption = "You have " & Y & " unfinished orders"
       Else
       (Do this just changing captions and colors of me.unfinished) 
       End If
Else
(Do change color and caption of me.isResolved.)
End If

我尝试了Else if和其他一些方法,但是当我在任何一行上运行调试停止时,如果满足第一个条件,它就会结束Sub。

使用Access

1 个答案:

答案 0 :(得分:0)

你可以让他们互相追随:

Sub MySub()
    If x > 0 Then
        ' Code if x is positive
    Else
        ' Code if x is not positive
    End If

    If y > 0 Then
        ' Code if y is positive
    Else
        ' Code if y is not positive
    End If
End Sub