If/Then with RadioButton
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,开发者_C百科 else a.field3, b.field3,"
strSQL = strSQL & "a.field5, b.field5,"
What should I be doing?
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.
精彩评论