【发布时间】:2017-06-01 16:34:36
【问题描述】:
让我们先说我的代码知识充其量是有限的。我通常理解这些概念,但从来没有很好地实施它们。也就是说,这里是我的一个项目中的一个 sn-p 代码。
Option Compare Database
Private Sub Form_Current()
If IsNull(Me![OPT-78 (5900EL)]) Then
Me![OPT-78 (5900EL)].Visible = False
Me![OPT-78 (5900EL) Label].Visible = False
Else
Me![OPT-78 (5900EL)].Visible = True
Me![OPT-78 (5900EL) Label].Visible = True
End If
If IsNull(Me![OPT-78 (7900EL)]) Then
Me![OPT-78 (7900EL)].Visible = False
Me![OPT-78 (7900EL) Label].Visible = False
Else
Me![OPT-78 (7900EL)].Visible = True
Me![OPT-78 (7900EL) Label].Visible = True
End If
If IsNull(Me![OPT-152 (4310B)]) Then
Me![OPT-152 (4310B)].Visible = False
Me![OPT-152 (4310B) Label].Visible = False
Else
Me![OPT-152 (4310B)].Visible = True
Me![OPT-152 (4310B) Label].Visible = True
End If
它位于“当前”事件的表单内。现在我知道通配符可以将所有这些 if then else 语句限制为一个简单优雅的单 if 语句解决方案,但我无法让它们工作。我试过 *、%、__ 和 ?,但没有运气。还有更多 if else 语句需要编写,所以我希望有一个更清洁的解决方案。
谢谢!
【问题讨论】:
-
也许可以使用
Select语句来缩短您的代码?