首页 > 解决方案 > Microsoft Access VBA - IF 语句总是计算 Else 表达式

问题描述

我想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

标签: databasems-accessif-statementvba

解决方案


尝试这个:

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

推荐阅读