如果/那么与单选按钮

发布于 2024-09-04 21:49:15 字数 735 浏览 5 评论 0原文

在我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

罪歌 2024-09-11 21:49:15

你应该使用存储过程。

只需构建两个不同的 strSql & 可能会使您的代码更干净一些。例如语句

strSQL = strBeginSQL1(strRiskSegment, "Detail")
strSQL = strSQL & "a.field1, b.field1,"
if (radiobutton2.value = true) then
strSQL = strSQL & "a.field4, b.field4"
else if (radiobutton3.value = true)
strSql = strSQL & "a.field3, b.field3"
endif
strSQL = strSQL & "a.field5, b.field5,"

,但这是一种糟糕的方法,您应该将这些变量传递给存储过程。

you should be using stored procedures.

It would probably make your code a little cleaner to just build two different strSql & statements for example

strSQL = strBeginSQL1(strRiskSegment, "Detail")
strSQL = strSQL & "a.field1, b.field1,"
if (radiobutton2.value = true) then
strSQL = strSQL & "a.field4, b.field4"
else if (radiobutton3.value = true)
strSql = strSQL & "a.field3, b.field3"
endif
strSQL = strSQL & "a.field5, b.field5,"

but this is a terrible way and you should just pass these variables to a stored proc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文