By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,471 Members | 2,192 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,471 IT Pros & Developers. It's quick & easy.

Retrieve Value of Grouped Radio Button

100+
P: 132
I have 2 radio buttons on a form...I need to know which was selected by the user in order to determine which report to send to the printer....This code is NOT getting it done...Any ideas??


If Forms!ReportForm![Option68].Value = True Then
Jan 31 '08 #1
Share this Question
Share on Google+
3 Replies


Delerna
Expert 100+
P: 1,134
I think its

If Forms!ReportForm![Option68].checked= True Then


By the way, get in the habbit of giving your controls sensible names.
It will make your code more readable and therefore easier to understand and change latter. Are you going to remember what Option68 is in 12 months after you relese it for use and a user encounters a problem has occurred and you need to track down what is causing it. A3 letter prefix in the name also tells you the type of control you are dealing with

optNameOfTheOptionControl
btnNameOfTheButtonControl
frmNameOfTheForm
tblNameOfTheTable
qryNameOfTheQuery

Just a suggestion !!
Jan 31 '08 #2

missinglinq
Expert 2.5K+
P: 3,532
An Option Group isn't boolean, it doesn't return True/False. Instead, an Option Group returns the value assigned to the given button/checkbox. The first item in the Group returns a 1, the second a 2, and so forth. If the name of your Option Group frame is YourOptionFrame (clever isn't it?) this code will do the trick:

Expand|Select|Wrap|Line Numbers
  1. Private Sub YourOptionFrame_Click()
  2.  Select Case YourOptionFrame
  3.    Case 1
  4.     'Code here to print "Report1"
  5.    Case 2
  6.     'Code here to print "Report2"
  7.  End Select
  8. End Sub
  9.  
You could also use

Expand|Select|Wrap|Line Numbers
  1. Private Sub YourOptionFrame_Click()
  2.    If YourOptionFrame = 1 Then
  3.      'Code here to print "Report1"
  4.   ElseIf YourOptionFrame = 2 Then
  5.       'Code here to print "Report2"
  6.   End IF
  7.  End Sub
  8.  
With just a couple of choices it probably doesn't matter which you use, but the first example, using the Select Case construct, makes things much clearer when you have a number of choices.

You could use the same code behind a command button, to be clicked after chosing a button.

BTW, Delerna's advice on giving meaningful names to controls is spot on!

Linq ;0)>
Feb 1 '08 #3

100+
P: 132
An Option Group isn't boolean, it doesn't return True/False. Instead, an Option Group returns the value assigned to the given button/checkbox. The first item in the Group returns a 1, the second a 2, and so forth. If the name of your Option Group frame is YourOptionFrame (clever isn't it?) this code will do the trick:

Expand|Select|Wrap|Line Numbers
  1. Private Sub YourOptionFrame_Click()
  2.  Select Case YourOptionFrame
  3.    Case 1
  4.     'Code here to print "Report1"
  5.    Case 2
  6.     'Code here to print "Report2"
  7.  End Select
  8. End Sub
  9.  
You could also use

Expand|Select|Wrap|Line Numbers
  1. Private Sub YourOptionFrame_Click()
  2.    If YourOptionFrame = 1 Then
  3.      'Code here to print "Report1"
  4.   ElseIf YourOptionFrame = 2 Then
  5.       'Code here to print "Report2"
  6.   End IF
  7.  End Sub
  8.  
With just a couple of choices it probably doesn't matter which you use, but the first example, using the Select Case construct, makes things much clearer when you have a number of choices.

You could use the same code behind a command button, to be clicked after chosing a button.

BTW, Delerna's advice on giving meaningful names to controls is spot on!

Linq ;0)>
Thanks, Guys! I'll incorporate the changes!
Feb 4 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.