2014-09-01 65 views
0

考慮:訪問2002/VBA - I如果

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正在返回語法錯誤。我看不出爲什麼 - 我錯過了什麼?

+1

用rsAddress(「address_line_2」)=「」'替換rsAddress(「address_line_2」)='''' – Matt 2014-09-01 01:41:50

回答

1

答案是,當然,我填塞了空串測試: rsAddress("address_line_2")=''

正確的語法是:rsAddress("address_line_2")=""用雙引號",而不是單引號'

+0

發生錯誤。只要你從他們那裏學習,沒有任何傷害。 – Matt 2014-09-01 01:51:38