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

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

我一直在试图找出如何在一个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

vba ms-access access-vba
1个回答
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
© www.soinside.com 2019 - 2024. All rights reserved.