使用select case和if for differents过程

时间:2016-05-23 21:29:12

标签: vba access-vba

调用程序时遇到问题。有两个:

Public Sub altaorange()
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)
With OutMail
    .To = "xxxx@orange.com"
    .CC = ""
    .BCC = ""
    .Subject = "Alta de línea. ATT MR"
    .Body = "Hello MR"
    'Se pueden adjuntar ficheros
    '.Attachments.Add ("C:\Mi_Fichero.pdf")
    .Display 'tambien se puede usar .Send y lo situa en la bandeja de salida
End With
Set OutMail = Nothing
Set OutApp = Nothing

End Sub

Public Sub bajaorange()
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)
With OutMail
    .To = "xxxx@orange.com"
    .CC = ""
    .BCC = ""
    .Subject = "Baja de línea . ATT MR"
    .Body =  "Hello MR"
    'Se pueden adjuntar ficheros
    '.Attachments.Add ("C:\Mi_Fichero.pdf")
    .Display 'tambien se puede usar .Send y lo situa en la bandeja de salida
End With
Set OutMail = Nothing
Set OutApp = Nothing

End Sub

当我调用第一个它正常工作时,它会加载正确的程序。我展示了代码:

Select Case operador

    Case Is = "ORANGE"

    'Alta de línea ORANGE

        If fam = "XX-YYYY" Or fam = "ZZ-WWWW" Then

            Call altaorange

        End if

     End Select

但如果我使用它:

    Case Is = "ORANGE"

        'Baja de línea ORANGE

        If fam = "XX-YYYY" Or fam = "ZZ-WWWW" And baja ="PPPPP" Or baja ="DDDDD" Then

           Call bajaorange

        End If
End Select

加载第一个程序(altaorange)。

我不知道它没有加载bajaorange proc。

1 个答案:

答案 0 :(得分:0)

Select Case将在第一场比赛中停止,两者都是Case Is = "ORANGE",它只会进入第一场比赛。

由于fam在两个实例中都与XX-YYYYZZ-WWWW具有相同的匹配,因此当您进入operador的第一个"ORANGE"匹配时,它会继续运行altaorange

baja视为决定性变量。我还使用下面的代码段来展示包围If ... Or/And ... Then语句的重要性的示例

If (operador = "ORANGE") and ((fam = "XX-YYYY") Or (fam = "ZZ-WWWW")) then
    If (baja ="PPPPP") Or (baja ="DDDDD") then
        Call bajaorange
    Else
        Call altaorange
    End If
End If