我想用一些文本作为条件构造一个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
当检查单个记录中没有迭代的单个字段所持有的值时,使用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
试试这个:
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