Vba 如果有别的事,就阻止麻烦
如果ElseIf块出现问题,我无法找出错误所在 我得到的信息是“没有if的Else” 如果您能提供任何帮助或指导,我对使用if-Elsei非常陌生 错误行:Vba 如果有别的事,就阻止麻烦,vba,ms-access,Vba,Ms Access,如果ElseIf块出现问题,我无法找出错误所在 我得到的信息是“没有if的Else” 如果您能提供任何帮助或指导,我对使用if-Elsei非常陌生 错误行: ElseIf booSM = True And _ booInv = True And _ booHOP = False _ Then strTo = Me.txtServiceManager.Column(1) & ";" & Me.txtInvestigator.Column(1
ElseIf booSM = True And _
booInv = True And _
booHOP = False _
Then strTo = Me.txtServiceManager.Column(1) & ";" & Me.txtInvestigator.Column(1)
完整代码:
Dim txtScan As String
Dim strTo As String
Dim booSM As Boolean
Dim booInv As Boolean
Dim booHOP As Boolean
Me.Refresh
txtScan = Me.txtScanLocation
booSM = booComDocSMSent
booInv = booComDocInvSent
booHOP = booComDocHOPSent
If booSM = True And _
booInv = True And _
booHOP = True _
Then strTo = Me.txtServiceManager.Column(1) & ";" & Me.txtInvestigator.Column(1) & ";" & Me.txtHop.Column(1)
ElseIf booSM = True And _
booInv = True And _
booHOP = False _
Then strTo = Me.txtServiceManager.Column(1) & ";" & Me.txtInvestigator.Column(1)
ElseIf booSM = True And _
booInv = False And _
booHOP = True _
Then strTo = Me.txtServiceManager.Column(1) & ";" & Me.txtHop.Column(1)
ElseIf booSM = False And _
booInv = True And _
booHOP = True _
Then strTo = Me.txtInvestigator.Column(1) & ";" & Me.txtHop.Column(1)
ElseIf booSM = True And _
booInv = False And _
booHOP = False _
Then strTo = Me.txtServiceManager.Column(1)
ElseIf booSM = False And _
booInv = True And _
booHOP = False _
Then strTo = Me.txtInvestigator.Column(1)
ElseIf booSM = False And _
booInv = False And _
booHOP = True _
Then strTo = Me.txtHop.Column(1)
End If
查看
If语句代码部分的以下逻辑:
Sub Logic()
'Attempt 1st
If a = 1 And _
b = 1 _
Then C = 1 'end of if statement
'Attempt 2nd
If a = 1 And _
b = 1 _
Then _
C = 1 'end of if statement
'Attempt 3rd
If a = 1 And _
b = 1 _
Then
C = 1 'and continuation below
ElseIf a = 1 And _
b = 1 _
Then
'something here
End If
End Sub
如果条件检查
,则有三种不同的写入逻辑。在您的情况下,您可能遗漏了一些uu下划线标记
,或者您应该将一些行移到下一行(在之后的代码,然后是
关键字) 我手头没有VBA,但看起来您的行尾有问题
格式
if condition then
statement
elesif conditon
statement
end if
您正在使用换行符(_),格式如下所示
if condition then statement
elseif condition then statement
endif
所以
也许对你更合适
或者如果你想保留一些多行格式
If booSM = True And _
booInv = True And _
booHOP = True Then
strTo = Me.txtServiceManager.Column(1) & ";" & Me.txtInvestigator.Column(1) & ";" & Me.txtHop.Column(1)
ElseIf booSM = True And _
booInv = True And _
booHOP = False _
Then
strTo = Me.txtServiceManager.Column(1) & ";" & Me.txtInvestigator.Column(1)
End If
错误消息是否会告诉您错误在哪一行?在出现错误的位置添加了一行。谢谢您,这行确实有效,但为什么在将该行移到Then语句下方后它才有效?这些只是我们都需要遵守的if语句的语法规则。有关更多信息,请尝试查看
If booSM = True And _
booInv = True And _
booHOP = True Then
strTo = Me.txtServiceManager.Column(1) & ";" & Me.txtInvestigator.Column(1) & ";" & Me.txtHop.Column(1)
ElseIf booSM = True And _
booInv = True And _
booHOP = False _
Then
strTo = Me.txtServiceManager.Column(1) & ";" & Me.txtInvestigator.Column(1)
End If