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

Setting an option radio button to input text

blyxx86
100+
P: 256
Alright, I understand how to make a query/report/etc display a text value based on what number the other column has in it..

(IIF([Field],"Pass","Fail")

But.. this can be a hamper on any query and I am told should not be used unless absolutely necessary.

I would like to set up a radio button to input a text value into a table instead of a number.

Perhaps it can be done with VB..
I have no idea how to actually write the code, but I'm guessing something having to do with this idea..

IF Form.Option108 = "1"
THEN [Table].[Fieldname]="Text"
ELSE [Table].[Fieldname]="Fail"
END IF

or something...
Nov 20 '06 #1
Share this Question
Share on Google+
12 Replies


MMcCarthy
Expert Mod 10K+
P: 14,534
The form will have to be bound to the aforementioned table and the field will have to be present on the form in a control.

Lets call the form frmResults, the Option Group optSuccess and the field txtFieldName. Then using a select case statement in the After Update event of the option group.

Expand|Select|Wrap|Line Numbers
  1.  Private Sub OptSuccess_AfterUpdate() 
  2.  
  3.   Select Case OptSuccess
  4.   Case 1
  5.      Me.txtFieldName = "Text"
  6.   Case 2
  7.      Me.txtFieldName = "Fail"
  8.   End Select
  9.  
  10. End Sub
  11.  
Nov 20 '06 #2

NeoPa
Expert Mod 15k+
P: 31,494
Radio buttons come within a Frame which has a number of Radio buttons in it.
Each RB will return a value of True or False.
Also, the Frame will have a value which matches the Radio button currently set to True.

Say I have a frame with three RBs numbered 1, 2 & 3.
If 3 is selected :
RB1 = False
RB2 = False
RB3 = True
Frame = 3

Mary, You pipped me again :(
(Nice code btw).
Nov 20 '06 #3

MMcCarthy
Expert Mod 10K+
P: 14,534

Mary, You pipped me again :(
(Nice code btw).
Still not converted, I always use select case in option group frames. It only make sense. Keep trying.

Mary ;)
Nov 20 '06 #4

NeoPa
Expert Mod 15k+
P: 31,494
I won't stop.
I'll teach you to appreciate code-beauty yet ;)
Nov 20 '06 #5

MMcCarthy
Expert Mod 10K+
P: 14,534
I won't stop.
I'll teach you to appreciate code-beauty yet ;)
Beauty is in the eye of the beholder.

Probably because I learned C before any other languages the logic of If statements work well in my very strange brain. And yes I do know there are case statements in C too.

Mary
Nov 20 '06 #6

NeoPa
Expert Mod 15k+
P: 31,494
Beauty is everywhere - for those with the eyes to see it ;)
Ooops - a deep moment.
Nov 20 '06 #7

blyxx86
100+
P: 256
What is a case statement? I do not quite understand what it does, or how the program knows that Case 1 is referring to Radio 1 being selected.

Also, should Case 1 be renamed to Case 0 because that is where access seems to start numbering things. 0 for false, -1 for true. That type of thing.

I like the code and it will do wonders for me.
Nov 21 '06 #8

MMcCarthy
Expert Mod 10K+
P: 14,534
What is a case statement? I do not quite understand what it does, or how the program knows that Case 1 is referring to Radio 1 being selected.

Also, should Case 1 be renamed to Case 0 because that is where access seems to start numbering things. 0 for false, -1 for true. That type of thing.

I like the code and it will do wonders for me.
Go to the option frame of the radio buttons and have a look at the properties. In particular the value that Access assigns to each radio button which will show when you click the button.

The case statement (or in access Select Case) is run on the option group ( the aforementioned frame).

Because the group itself is an object then access assigns 1, 2, 3 etc. by default to each of the buttons. The select case statement just checks what the current value of the group is i.e. which radio button is selected.

I checks the value
Nov 21 '06 #9

NeoPa
Expert Mod 15k+
P: 31,494
See below for full syntax of the Select Case Statement.
Basically you check an expression and have a list of Case Statements which get run depending on the value of the expression.
A sneaky trick, to base it on separate expressions, is to use TRUE as the expression (testexpression) and various cjecks in the Case Statements.

Select Case Statement


Executes one of several groups of statements, depending on the value of an expression.

Syntax

Select Case testexpression
[Case expressionlist-n
[statements-n]] ...
[Case Else
[elsestatements]]

End Select

The Select Case statement syntax has these parts:

Part Description
testexpression Required. Any numeric expression or string expression.
expressionlist-n Required if a Case appears. Delimited list of one or more of the following forms: expression, expression To expression, Is comparisonoperator expression. The To keyword specifies a range of values. If you use the To keyword, the smaller value must appear before To. Use the Is keyword with comparison operators (except Is and Like) to specify a range of values. If not supplied, the Is keyword is automatically inserted.
statements-n Optional. One or more statements executed if testexpression matches any part of expressionlist-n.
elsestatements Optional. One or more statements executed if testexpression doesn't match any of the Case clause.
Nov 21 '06 #10

blyxx86
100+
P: 256
If that's the case (no pun intended) then is it possible to use your code:
Expand|Select|Wrap|Line Numbers
  1.  Private Sub OptSuccess_AfterUpdate() 
  2.  
  3.   Select Case OptSuccess
  4.   Case 1
  5.      Me.txtFieldName = "Text"
  6.   Case 2
  7.      Me.txtFieldName = "Fail"
  8.   End Select
  9.  
  10. End Sub
  11.  
And have Case 2 equal multiple expressions. You can assign the same value to multiple Radio buttons (at least my experience, but never actually USED them.)
So I could have 4 options, and only one would return a value of 1, while the others return 0. Would that be true?

And is it now possible to have txtFieldName not displayed on the form? I want the option to update the field in the table, but I do not want the form to have the extra fields if it can be done without them. instead of. me.txtFieldName could I use a full path? Like to Tbl.TableName.FieldName (I have no idea what the actual code for something like this would be though, just a thought.)

Go to the option frame of the radio buttons and have a look at the properties. In particular the value that Access assigns to each radio button which will show when you click the button.

The case statement (or in access Select Case) is run on the option group ( the aforementioned frame).

Because the group itself is an object then access assigns 1, 2, 3 etc. by default to each of the buttons. The select case statement just checks what the current value of the group is i.e. which radio button is selected.

I checks the value
Nov 21 '06 #11

NeoPa
Expert Mod 15k+
P: 31,494
If you look at the 'Select Case' statement Help you will see that you don't need to go to the trouble of setting multiple buttons to the same value.
You can have a case statement with multiple option in a list :
Expand|Select|Wrap|Line Numbers
  1. Case 1, 2, 4 To 6
if you want.
Nov 21 '06 #12

P: 1
Hi,

I came across your answer to this post, I tried the code as follows,

Expand|Select|Wrap|Line Numbers
  1.  Private Sub Frame1_AfterUpdate()
  2.  
  3.     Select Case Frame1
  4.  
  5.     Case 1
  6.         Me.High = "High"
  7.  
  8.     Case 2
  9.         Me.High = "Low"
  10.  
  11.     Case 3
  12.         Me.High = "N/A"
  13.  
  14.     End Select
  15.     End Sub
  16.  
What I find is that the text gets transferred to the table as required, but the shading of the option button goes grayed out, and if I move on to another field, all three option buttons on this page grey out.

How can I alter this so that the selected option button stays selected, when moving from field to field.
Thanks in advance, hopefully what I'm after makes sense.

Newbeetle86



The form will have to be bound to the aforementioned table and the field will have to be present on the form in a control.

Lets call the form frmResults, the Option Group optSuccess and the field txtFieldName. Then using a select case statement in the After Update event of the option group.

Expand|Select|Wrap|Line Numbers
  1.  Private Sub OptSuccess_AfterUpdate() 
  2.  
  3.   Select Case OptSuccess
  4.   Case 1
  5.      Me.txtFieldName = "Text"
  6.   Case 2
  7.      Me.txtFieldName = "Fail"
  8.   End Select
  9.  
  10. End Sub
  11.  
Jun 20 '07 #13

Post your reply

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