我想使用一些文本作为条件构造一个if
语句。
在我的字段Status_anggota
中有一个组合框,其值为"Active"
或"Not active"
。
我的问题是它不会获得"Active"
的值,因此它只显示错误的语句:
Set db = CurrentDb()
Set rs = db.OpenRecordset("Select Status_anggota from Tbl_anggota Where Kode_anggota='" & Text2 & "'")
If rs.RecordCount = "Active" Then
MsgBox "Status is active", vbInformation
Else
MsgBox "Status is not active", vbInformation
End If
答案 0 :(得分:0)
尝试一下:
Set db = CurrentDb()
Set rs = db.OpenRecordset("Select Status_anggota from Tbl_anggota Where Kode_anggota='" & Text2 & "'")
If rs!Status_anggota.Value = "Active" Then
MsgBox "Status is active", vbInformation
Else
MsgBox "Status is not active", vbInformation
End If
答案 1 :(得分:0)
检查没有重复的单个记录中单个字段的值时,通常更容易使用DLookup
函数,例如:
If DLookup("Status_anggota", "Tbl_anggota", "Kode_anggota='" & Text2 & "'") = "Active" Then
MsgBox "Status is active", vbInformation
Else
MsgBox "Status is not active", vbInformation
End If