We help IT Professionals succeed at work.

Placing radio button control on form on runtime

pak_slm
pak_slm asked
on
619 Views
Last Modified: 2013-12-26
I want to place radio button control in a frame on runtime on the base of rows return by a query.

Means if query return 5 rows then place 5 radio button and so on.

please guide with code.
Comment
Watch Question

Commented:
Try adding a radio button to your frame (Option1) and change the index property to 0. Then try this to add more option buttons:

Private Sub Command1_Click()
Load Option1(1)
Option1(1).Top = Option1(1 - 1).Top + Option1(1 - 1).Height
Option1(1).Visible = True

Load Option1(2)
Option1(2).Top = Option1(2 - 1).Top + Option1(2 - 1).Height
Option1(2).Visible = True

Load Option1(3)
Option1(3).Top = Option1(3 - 1).Top + Option1(3 - 1).Height
Option1(3).Visible = True

End Sub

Author

Commented:
Also need to resize frame and form height with radio button.

Commented:
You could use a select case statement in the option buttons click event.For example,this will change the form and frame height when you select  Option1(3)


Private Sub Option1_Click(Index As Integer)
Select Case Index
    Case 1
   
    Case 2
   
    Case 3
        If Option1(3).Value = True Then
            Form1.Height = 6000
            Frame1.Height = 3000
        End If
End Select
End Sub

Author

Commented:
vinnyd79

I try code it is ok
I also check within recordset loop it is ok

How i know which is clicked.

Commented:
You can tell by the index passed to the option buttons click event.For example:

Private Sub Option1_Click(Index As Integer)
Select Case Index
    Case 1
        MsgBox "Option1(1) has been clicked"
    Case 2
        MsgBox "Option1(2) has been clicked"
    Case 3
        MsgBox "Option1(3) has been clicked"
        Form1.Height = 6000
        Frame1.Height = 3000
End Select
End Sub

Commented:
do not accept this as an answer

If you don't know how many

just do

Private Sub Option1_Click(Index As Integer)
MsgBox "Option1(" & index & ") has been clicked"

End Sub
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
jasonholland

Very nice, One thing more need to be clear

i have query like

select code, desc from table1

i want to set option button caption as desc and when i click one of those then code should be return.

please guide with code accordingly.


Could you please post a couple of your code, desc pairs from your database. It really depends on how much data is being held in the code
record as to how I would deal with it. Either way, it can be done without a prob...

Jason Holland

Author

Commented:
jasonholland

i have used procedure Private Sub Command2_Click() and set filter on Rs on the base of selected option button caption and get Code.

   
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.