Using radio buttons to fill in fields on a form (1 Viewer)

joeyo34

Registered User.
Local time
Yesterday, 19:00
Joined
Aug 20, 2007
Messages
40
I am working with a form that is going to have 2 radio buttons or 1 option group. All I want to do is have one of the fields automatically fill in with a numeric value if one radio button is clicked, or clear any value in that field if the other radio button is clicked. Unfortunately this task has become quite difficult to accomplish.

I assigned values to the option buttons first and then tried to use VB code to auto-fill a particular field with the correct numeric value based on the value of the radio button, but am not very good with VB and this did not work.

I also tried to assign the actual value of the radio button to be the value I want to show up in the field and bind the radio button to that field. This works quite well for the numeric value button, but it does not work for the button that should clear the value in the cell because it will not allow me to have a null value for a radio button value. Any ideas on how to accomplish this task? Thanks in advance!
 

DevastatioN

Registered User.
Local time
Yesterday, 20:00
Joined
Nov 21, 2007
Messages
242
Assuming that your textbox is named "txtValue", and that your option group containing the radio buttons is called "grpOption" (with value 1 being the top radio button and value 2 being the bottom radio button) you can use the following code in the on click event of the option group:

Private Sub grpOption_Click()
Select Case grpOption
Case 1
txtValue = "1"
Case 2
txtValue = Null
End Select
End Sub

This will fill a "1" into the textbox when the top option is clicked, and the textbox becomes empty when the bottom option is clicked.
 

joeyo34

Registered User.
Local time
Yesterday, 19:00
Joined
Aug 20, 2007
Messages
40
where do you name the option group?

How would I determine the name of the option group. I can find the name of each of the radio buttons (in this case Option103 on top and Option105 on bottom) but I am unable to find out what the group itself is called. I think that once I can determine this I should be good to go! Thanks for the help.
 

missinglinq

AWF VIP
Local time
Yesterday, 19:00
Joined
Jun 20, 2003
Messages
6,423
If I undewrstand you correctly, this should do the job! You need to place a field in your table that you'll bind to your Option Group Frame. Set its datatype as Number.

On your form, place an Option Group Frame. Run thru the wizard, accepting the standard values (1,2 etc.) Select "I don't want a default". OPpt for "Store Value in this Field" and select the field you placed in your table for your option group. Close the wizard. Select the frame and name it YourOptionGroupFrame. Now place this code in its AfterUpdate event, replacing the 1000 withwhatever value you want:

Code:
Private Sub YourOptionGroupFrame_AfterUpdate()
If Me.YourOptionGroupFrame = 1 Then
 Me.YourField = 1000
Else
 Me.YourField = ""
End If
End Sub
 

DevastatioN

Registered User.
Local time
Yesterday, 20:00
Joined
Nov 21, 2007
Messages
242
You can find the name of the option group by right clicking on the boarder around the radio buttons and clicking properties. If you do not have an option group (you added the radio buttons manually) I would suggest adding an option group using the form toolbar.
 

joeyo34

Registered User.
Local time
Yesterday, 19:00
Joined
Aug 20, 2007
Messages
40
Working but still one problem

Alright....between the two posts I have got it to work properly! The only problem is when I click on each of my option buttons there is no black dot in the middle of the one that is selected. Is this a glitch or have I dont something wrong? Thanks for both of your help by the way!!!
 

DevastatioN

Registered User.
Local time
Yesterday, 20:00
Joined
Nov 21, 2007
Messages
242
I have not run into that problem here. It could be a glitch. Try remaking the option group again from scratch just to see if that fixes the problem.
 

joeyo34

Registered User.
Local time
Yesterday, 19:00
Joined
Aug 20, 2007
Messages
40
Might still be a glitch, but I remade the option group and it still is messing up. I may have to redo the form as well. Thank you for your help on this!!! I will get back to you all if I determine what the glitch is or why it exists. Thanks again!
 

DevastatioN

Registered User.
Local time
Yesterday, 20:00
Joined
Nov 21, 2007
Messages
242
You're welcome.

I'm interested to find out why that is happening if youfigure it out.
 

DevastatioN

Registered User.
Local time
Yesterday, 20:00
Joined
Nov 21, 2007
Messages
242
You're welcome.

I'm interested to find out why that is happening if youfigure it out.
 

missinglinq

AWF VIP
Local time
Yesterday, 19:00
Joined
Jun 20, 2003
Messages
6,423
Do you have your option group or the individual radio button bound to a field in your underlying table, and if so, what is the datatype?
 

joeyo34

Registered User.
Local time
Yesterday, 19:00
Joined
Aug 20, 2007
Messages
40
I have yet to figure out what the glitch was necessarily, but I have since been able to make the radio buttons work properly and the dot in the middle signifying which one was chosen is there now. I have no idea what could have caused the problem, as I tried to make the same buttons on a different form using the same code and it worked? Oh well:) Thanks again for all the help...I'm sure I'll need it again sometime!
 

Users who are viewing this thread

Top Bottom