Radio Buttons Programming

J

Joe

Hello All,

I need help programming on radio buttons. On a form is an option group with
two radio buttons, daily and monthly. When the user clicks on the Daily
button the cmdDailyPmts command button should be visible. When the user
clicks on the Monthly button the cmdMonthlyPmts command button should be
visible and the cmdDailyPmts should hide. Eventually, the Daily is the
default radio button and the cmdDailyPmts should always be visible.

This is what I have but its not working
IF rdoDaily = 1 THEN
cmdDailyPmts.visible = true
cmdMonthlyPmts.visible = false
else
cmdDailyPmts.visible = false
cmdMonthlyPmts.visible = true
end if
 
C

Clifford Bass

Hi Joe,

You need to use a combination of the option group and the button itself:

If optiongroupName.Value = rdoDaily.OptionValue Then
...

Using the OptionValue property allows you to avoid hard coding the
actual value (1, 2, 3, etc.). If you change them in the buttons' properties,
the code will still work, without the need to make any changes.

I prefer to use the Select Case statement for these as it is neatly
organized, especially if there are a lot of radio buttons. I also like to
include a Case Else section:

Select Case optiongroupName.Value
Case rdoDaily.OptionValue
' ...

Case rdoMonthly.OptionValue
' ...

Case Else
Debug.Assert False
MsgBox "Uh oh!"

End Select

Hope that helps,

Clifford Bass
 
A

Arvin Meyer [MVP]

Why not just run your code from the radio buttons? I see no reason for the
command buttons at all (air code):

Sub MyOptGrp_AfterUpdate()
Select Case MyOptGrp
Case 1
DoCmd.OpenReport "Daily"
Case 2
DoCmd.OpenReport "Monthly"
End Sub
 
J

Joe

Thank you all for your response... I tried all three options and used
steves. It seamed a little easier in to figure out being new to programming
:)
 
C

Clifford Bass

Hi Joe,

You are welcome. The only substancial difference between Steve's and
my suggestion is that his hard codes the actual values. So you will have to
remember to change them in the code if you ever change them in the form. And
my code will alert you if you ever add more and forget to add in the code to
deal with them.

Clifford Bass
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top