Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Questions regarding Radio Buttons

Status
Not open for further replies.

jontout

Technical User
Dec 29, 2006
95
GB
Hi.

I've created a voting form with (currently) 10 option groups comprising of 5 mutually exclusive radio buttons with the headings; For, Against, Abstain, Spoil and Proxy. So far I'm up to 50 buttons but their could be more option groups and I fear the coding will get messy.

Here are my initial problems / queries.

Is it possible (and pointers would be welcome) to store the individual values of each button (currently 1-5) in a database table and use a query to feed 'default selections, ie if the voter is following the 'Chair Vote', currently the code reads as follows, where values 1 & 2 are either For or Against.

Code:
If GrpChair.Value = 1 Then
OptRes1.Value = 1
OptRes2.Value = 2
OptRes3.Value = 1
OptRes4.Value = 2
OptRes5.Value = 1
OptRes6.Value = 2
OptRes7.Value = 1
OptRes8.Value = 2
OptRes9.Value = 1
OptRes10.Value = 2

GrpChair is the Option Group, a secondary radio button clears the form using a .value of null, but again coding longhand.

Any help will be gratefully accepted.

Cheers,

Jon





 
How are ya jontout . . .

Not quite sure about your setup, but as far as setting defaults, in the [blue]Tag[/blue] property of each option group, enter the index of the default radio button desired. Then in the forms [blue]OnLoad[/blue] event, copy/paste the following:
Code:
[blue]   Dim ctl As Control
   
   For Each ctl In Me.Controls
      If Trim(ctl.Tag & "") <> "" Then ctl.DefaultValue = ctl.Tag
   Next[/blue]
Thats it! . . .

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Thanks Aceman, I only want to use the above (my code) values when a user selects the option that fires in the defaults, so I'll use it in a macro, OnLoad needs to have no radio buttons selected. I think I might be able to fiddle about with your code and have it read these selections from a table, which should save me recoding ever time the 'managers' need a change.

Cheers,

Jon
 
Have you considered a table of possibilities?

tblOptions
OptionID
OptionName
OptionDefaultValue

tblPersonOptions
PersonID
OptionID
OptionValue

These could easily be displayed in a subform.

You may wish to read
 
That's kind of what I'm considering, but when you offer the suggestion of, "table of possibilities", you only mean default option?

As it's an open voting form for 50,000 voters (not in Florida) then I'd have to think of that possibility times by the number of options :)
 
I am not quite sure what you mean. The table of possibilities relates to the option groups. It needs to be completed. The table tblPersonOptions is empty and lines are added as a person selects an option.
 
oh, ok - that's what I'm currently using.

What I'm looking to do is change my code so that when the user clicks on a Chair Vote button, the Radio Buttons pick up corresponding values as per my code at the start of this thread, but taking those values from a database table.

The following code comes close, but rather than have to recode the Tag values of the radio buttons, I'd like to make the change in a database.


For Each ctl In Me.Controls
If Trim(ctl.Tag & "") <> "" Then ctl.DefaultValue = ctl.Tag
Next

 
If this is a continuous form, it seems to me you could bind the option controls to the relevant field in the table.
 
Here's what I've come up with, tested and working!
It might be of use to someone else.

Code:
sSQL = "Select * from tblChair"
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(sSQL)

    If Not rst.BOF Then rst.MoveFirst
    Do Until rst.EOF
    
        For Each ctl In Me.Controls
        Select Case ctl.ControlType
        Case acOptionGroup
        If (ctl.ControlName = rst.Fields("Resolution")) Then
        ctl.Value = rst.Fields("Vote")
        End If
        Case Else
        End Select
        Next ctl
    
    rst.MoveNext
    Loop

rst.Close
Set rst = Nothing
The key section are these following lines, where the OptionGroup value is stored in a database table with the default and when the ControlName finds that value, it gives the button the corresponding query.

If (ctl.ControlName = rst.Fields("Resolution")) Then
ctl.Value = rst.Fields("Vote")
End If

Hope this is of use.

Cheers,

Jon

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top