考虑:
sqlAddress = "SELECT " _
& "address_line_1, address_line_2, city, postcode, state " _
& "FROM contacts " _
& "WHERE (contact_id =" & contact_id & ")"
Set rsAddress = dbs.OpenRecordset(sqlAddress)
If Not rsAddress.EOF Then
addressStr = IIf(rsAddress("address_line_2")='', rsAddress("address_line_1") & Chr(13) + Chr(10) & rsAddress("city") & Chr(13) + Chr(10) & rsAddress("postcode") & Chr(13) + Chr(10) & rsAddress("state"), rsAddress("address_line_1") & Chr(13) + Chr(10) & rsAddress("address_line_2") & Chr(13) + Chr(10) & rsAddress("city") & Chr(13) + Chr(10) & rsAddress("postcode") & Chr(13) + Chr(10) & rsAddress("state"))
Me.vcTBAddress.SetFocus
Me.vcTBAddress = addressStr
End If
我想要做的是只显示address_line_2,以防它不为空并且不是空字符串。 IIf返回语法错误。我不明白为什么 - 我错过了什么?
答案 0 :(得分:1)
答案当然是我填空了空字符串测试:
rsAddress("address_line_2")=''
。
正确的语法是:rsAddress("address_line_2")=""
带双引号"
,而不是单引号'
。