If ElseIf生成编译错误:不带If的Else



调试时,它会在Elseif行上停止并突出显示me.cboKillRemaining

我认为这个问题本身就包含在下面的代码中。

Dim Result As String
Dim Path As String
'Determine path
If (IsNull(Me.cboKillRemaining) Or Me.cboKillRemaining = "No") And Me.txtRemClones > 0 Then
Result = MsgBox("Create " & Me.txtNumofTags & " tags from " & Me.cboGroup & " and leave remaining " & Me.txtRemClones & " clones active?", vbYesNo, "Confirm transplant")
If Result = vbYes Then Path = 1
Else: Path = 4
End If

ElseIf Me.txtRemClones > 0 And Me.cboKillRemaining = "Yes" Then
Result = MsgBox("Create " & Me.txtNumofTags & " tags from " & Me.cboGroup & ", kill remaining " & Me.txtRemClones & ", and inactivate clone group?", vbYesNo, "Confirm transplant")
If Result = vbYes Then Path = 2
Else: Path = 4
End If

Else 'None remaining do not need to ask to kill clones
Result = MsgBox("Create " & Me.txtNumofTags & " tags from " & Me.cboGroup & " and inactivate clone group?", vbYesNo, "Confirm transplant")
If Result = vbYes Then Path = 3
Else: Path = 4
End If
End If

您不应该使用钝语法,它并不常见。多花几行,你就应该做好准备了。此外,调整声明:

Dim Result As VbMsgBoxResult
Dim Path As Integer
'Determine path
If (IsNull(Me.cboKillRemaining) Or Me.cboKillRemaining = "No") And Me.txtRemClones > 0 Then
Result = MsgBox("Create " & Me.txtNumofTags & " tags from " & Me.cboGroup & " and leave remaining " & Me.txtRemClones & " clones active?", vbYesNo, "Confirm transplant")
If Result = vbYes Then 
Path = 1
Else
Path = 4
End If
ElseIf Me.txtRemClones > 0 And Me.cboKillRemaining = "Yes" Then
Result = MsgBox("Create " & Me.txtNumofTags & " tags from " & Me.cboGroup & ", kill remaining " & Me.txtRemClones & ", and inactivate clone group?", vbYesNo, "Confirm transplant")
If Result = vbYes Then 
Path = 2
Else
Path = 4
End If
Else 'None remaining do not need to ask to kill clones
Result = MsgBox("Create " & Me.txtNumofTags & " tags from " & Me.cboGroup & " and inactivate clone group?", vbYesNo, "Confirm transplant")
If Result = vbYes Then 
Path = 3
Else
Path = 4
End If
End If

最新更新