如果/那么与单选按钮
在我的 VBA 代码中,我查询 SQL 表。我想添加一个 if/then 语句,这样如果选择一个单选按钮,它会提取一个特定值,如果选择另一个单选按钮,它会提取一个不同的值。我的 if 是 radiobutton1,我的 else 是 radiobutton2,尽管 else 可以只是取另一个值。
下面是代码的具体部分:
strSQL = strBeginSQL1(strRiskSegment, "Detail")
strSQL = strSQL & "a.field1, b.field1, "
strSQL = strSQL & "a.field2, b.field2, a.field3, b.field3,"
如果我的 if/then 是针对 field3(单选按钮将指向 field4)。
此时我该如何添加 if/then 语句?我想应该是:
strSQL = strBeginSQL1(strRiskSegment, "Detail")
strSQL = strSQL & "a.field1, b.field1,"
strSQL = strSQL & "a.field2, b.field2, If radiobutton2.true then a.field4, b.field4, else a.field3, b.field3,"
strSQL = strSQL & "a.field5, b.field5,"
我应该做什么?
In my VBA code, I query a SQL table. I want to add an if/then statement so if one radio button is selected it pulls a certain value, and if the other radio button is selected, it pulls a different value. My if is radiobutton1, and my else is radiobutton2, although the else can just be to take the other value.
Here's the specific part of the code:
strSQL = strBeginSQL1(strRiskSegment, "Detail")
strSQL = strSQL & "a.field1, b.field1, "
strSQL = strSQL & "a.field2, b.field2, a.field3, b.field3,"
If my if/then is for field3 (the radio button will point to field4.)
How do I add the if/then statement in at this point? I thought it would be:
strSQL = strBeginSQL1(strRiskSegment, "Detail")
strSQL = strSQL & "a.field1, b.field1,"
strSQL = strSQL & "a.field2, b.field2, If radiobutton2.true then a.field4, b.field4, else a.field3, b.field3,"
strSQL = strSQL & "a.field5, b.field5,"
What should I be doing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你应该使用存储过程。
只需构建两个不同的 strSql & 可能会使您的代码更干净一些。例如语句
,但这是一种糟糕的方法,您应该将这些变量传递给存储过程。
you should be using stored procedures.
It would probably make your code a little cleaner to just build two different strSql & statements for example
but this is a terrible way and you should just pass these variables to a stored proc.