Объедините несколько операторов if в один - PullRequest
0 голосов
/ 08 октября 2019

Вероятно, это простое решение, но у меня проблемы с тем, чтобы что-нибудь заработало. Может быть просто синтаксис.

По сути, я хочу объединить их, чтобы вместо 5. появилось одно окно сообщения.

If Me.Status_Mfg_Engineer <> "Approved" Then MsgBox "MFG Engineer has not approved"
If Me.Status_Quality <> "Approved" Then MsgBox "Quality has not approved"
If Me.Status_Production <> "Approved" Then MsgBox "Production has not approved"
If Me.Status_Product_Engineer <> "Approved" Then MsgBox "Product Engineer has not approved"
If Me.Status_Other <> "Approved" Then MsgBox "Other has not approved" 

Ответы [ 3 ]

1 голос
/ 08 октября 2019

Если вы хотите проверить все элементы, а затем выдать одно составное сообщение, рассмотрите:

Dim strMsg As String
If Me.Status_Mfg_Engineer <> "Approved" Then strMsg = "MFG Engineer" & vbCrLf
If Me.Status_Quality <> "Approved" Then strMsg = strMsg & "Quality" & vbCrLf
If Me.Status_Production <> "Approved" Then strMsg = strMsg & "Production" & vbCrLf
If Me.Status_Product_Engineer <> "Approved" Then strMsg = strMsg & "Product Engineer" & vbCrLf
If Me.Status_Other <> "Approved" Then strMsg = strMsg & "Other" & vbCrLf
If strMsg <> "" Then MsgBox "Items not approved: " & vbCrLf & strMsg
1 голос
/ 08 октября 2019

Вы хотите одно окно сообщения, которое суммирует, какие агенты не одобрили.

Dim myPrompt as string
myPrompt=vbnullstring

If Me.Status_Mfg_Engineer <> "Approved" Then myPrompt= "MFG Engineer has not approved"
If Me.Status_Quality <> "Approved" Then myPrompt=myPrompt & vbcrlf & "Quality has not approved"
If Me.Status_Production <> "Approved" Then myPrompt=myPrompt & vbcrlf & "Production has not approved"
If Me.Status_Product_Engineer <> "Approved" Then myPrompt=myPrompt & vbcrlf & "Product Engineer has not approved"
If Me.Status_Other <> "Approved" Then myPrompt=myPrompt & vbcrlf & "Other has not approved" 

MsgBox _
    Title:="Missing approvals", _
    Prompt:=myPrompt, _
    Buttons:=vbOkOnly
1 голос
/ 08 октября 2019

Вы можете сделать это с помощью If.. ElseIf .. Else

If Me.Status_Mfg_Engineer <> "Approved" Then MsgBox "MFG Engineer has not approved"
ElseIf Me.Status_Quality <> "Approved" Then MsgBox "Quality has not approved"
ElseIf Me.Status_Production <> "Approved" Then MsgBox "Production has not approved"
ElseIf Me.Status_Product_Engineer <> "Approved" Then MsgBox "Product Engineer has not approved"
ElseIf Me.Status_Other <> "Approved" Then MsgBox "Other has not approved"
End If 

Редактировать 2: Ах, да (@ June7) - согласно документам здесь

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...