For Information. Which Radio Button in the list is checked

laredo512

Regular
Joined
Jan 6, 2004
Messages
88
Location
Far enough to see snow in winter
For the advanced crowd, this is most likely the simplest and perhaps the supidest thing you've seen posted here, but for newbies, this could save alot of coding time...

Say you have a form that has multiple radio buttons in the same list, groupbox or form and you want to trigger different events for each radio button that is checked at the time you program final input checking, a simple select statement can help you with this.

So, let's say you have three radio buttons and want to find out which is checked:

radYES
radNO
RadCANCEL

Visual Basic:
 [size=2][color=#0000ff]
Select [/color][/size][size=2][color=#0000ff]Case [/color][/size][size=2][color=#0000ff]True
 


[indent][/color][/size][size=2][color=#0000ff]Case [/color][/size][size=2][color=#0000ff]Is[/color][/size][size=2] = [/size][size=2][color=#0000ff]Me[/color][/size][size=2].radYES.Checked

 
 
[/size][size=2][color=#008000]'YES selected
 
[/color][/size][size=2][color=#0000ff]Case [/color][/size][size=2][color=#0000ff]Is[/color][/size][size=2] = [/size][size=2][color=#0000ff]Me[/color][/size][size=2].radNO.Checked
 
[/size][size=2][color=#008000]'NO Selected
 
[/color][/size][size=2][color=#0000ff]Case [/color][/size][size=2][color=#0000ff]Is[/color][/size][size=2] = [/size][size=2][color=#0000ff]Me[/color][/size][size=2].radCANCEL.Checked
 
[/size][size=2][color=#008000]'CANCEL Selected
 

[/indent][/color][/size][size=2][color=#0000ff]End [/color][/size][size=2][color=#0000ff]Select

 
 
[/color][/size]

Personnally, I use this when I run final checks on the form inputs before sending the info to the database. It permits me to modify data based on which option is checked by the user.

Hope this can help a few.
 
Well, first of all, the Is = part is unnecessary, because Me.radYes.Checked is a boolean anyway.

And besides, what would be the advantage over just using an If Else block?
If Me.radYESChecked Then
ElseIf Me.radNOChecked Then
ElseIf Me.radCANCEL.Checked Then
End If
it would be less typing and more intuitive.
:)
 
Back
Top