访问中的VBA ......如果那么

时间:2014-05-06 04:34:21

标签: access-vba

我正在尝试制作一个条件语句,基本上会说如果field1 + field2 =" string"然后做一些事情...我很确定我的东西部分正确,但我不认为我的条件陈述是正确的...这就是我所拥有的

txtTeam.Visible = True
If ([GuestFirstName] + [GuestLastName] = "Angela Cockrill") Then
    [LifetimeTxt] = "Trips of a Lifetime!"
    txtTeam.ForeColor = vbOrange
    txtTeam.FontSize = 14
    txtTeam.FontBold = True

Else
    txtTeam.Visible = False
    txtTeam.ForeColor = 0

End If

2 个答案:

答案 0 :(得分:1)

在MS Access VBA中,我会使用&符号运算符&将两个字符串连接在一起,而不是加号,但这只是一个偏好。您也可能需要考虑空间,例如

txtTeam.Visible = True
If ([GuestFirstName] & " " & [GuestLastName] = "Angela Cockrill") Then
    [LifetimeTxt] = "Trips of a Lifetime!"
    txtTeam.ForeColor = vbOrange
    txtTeam.FontSize = 14
    txtTeam.FontBold = True

Else
    txtTeam.Visible = False
    txtTeam.ForeColor = 0

End If

答案 1 :(得分:0)

根据您在字段中的内容,您可能需要添加空格,以及使用&符号:

If ([GuestFirstName] & " " & [GuestLastName] = "Angela Cockrill") Then