Solved

Placing radio button control on form on runtime

Posted on 2004-03-26
10
579 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.
0
Comment
Question by:pak_slm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 28

Expert Comment

by:vinnyd79
ID: 10686630
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
0
 
LVL 1

Author Comment

by:pak_slm
ID: 10686713
Also need to resize frame and form height with radio button.
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 10686879
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
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 1

Author Comment

by:pak_slm
ID: 10687182
vinnyd79

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

How i know which is clicked.

0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 10687347
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
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 10687648
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
0
 
LVL 2

Accepted Solution

by:
jasonholland earned 125 total points
ID: 10688845
Here ya go, this should make it completely explanatory.

My code here is a bit tighter, and more dynamic. Just create a new VB Standard EXE,
copy all of the code below into form1, and follow the instructions in the comments.

If you need more help, post another question.



'// Create a standard VB exe
'//
'// Leave Form1 as Form1
'// Create a command button, leave the name as command1, change the caption to "Records Returned"
'// Create another command button, leave the name as command2, change the caption to "Which one is selected"
'// Create a frame, leave the name as Frame1
'// Create 1 option (radio button) on the frame. Make sure it is on the frame.
'// Leave the name as Option 1, change the caption to "Option1(0), change the index value to 0
'// this will initialize it as an array, set Option1's height to 255, or whatever you like. I used 255.

Private Sub Command1_Click()
    '// This simulates the number of records returned from your query
    Dim i As Integer
    i = InputBox("How many records were returned?", "Return Record Count")
    '// When you get the number of records returned, call the sub like this
    Call DBQueryReturn(i)
End Sub

Sub DBQueryReturn(recordsReturned As Integer)

'// call this with the number of records returned from your query
Dim c, o As Integer
'// Start of the array
o = 1
'// This is the current count in the array
c = Form1.Option1.Count
'// As long as the new return amount is not 0, start adding option buttons
    If recordsReturned > 0 Then
        '// keep adding the option buttons until we are done
        Do While o <= recordsReturned
            '// create a new option button object
            Load Option1(c)
            '// change the forms height, adding the height of the new option control
            Form1.Height = Form1.Height + Option1(c).Height
            '// change the frames height, adding the height of the new option control
            Form1.Frame1.Height = Form1.Frame1.Height + Option1(c).Height
            '// put the new option control under the last one on the form, the 10 is for a small gap between them
            Form1.Option1(c).Top = Form1.Option1(c - 1).Top + Form1.Option1(c).Height + 10
            '// Set the options to visible
            Form1.Option1(c).Visible = True
            '// Change the caption
            Form1.Option1(c).Caption = "Option1(" & c & ")"
            c = c + 1
            o = o + 1
        Loop
    End If

End Sub

Private Sub Command2_Click()
    '// This just shows you how to figure out which one was selected
    Dim vControl As Variant
    Dim x As Integer
    x = 0
    '// loop through all of the option controls on form1
    For Each vControl In Form1.Option1
        '// if the current one is selected
        If Form1.Option1(x).Value = True Then
            '// show a message box
            MsgBox "Option1(" & x & ") was selected"
        End If
        x = x + 1
    Next
End Sub

Private Sub Form_Resize()
    '// Move the command buttons down the form so that it is still visible
    Form1.Command1.Top = Form1.ScaleHeight - Form1.Command1.Height - 25
    Form1.Command2.Top = Form1.ScaleHeight - Form1.Command2.Height - 25
End Sub



Good luck
Jason
0
 
LVL 1

Author Comment

by:pak_slm
ID: 10694138
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.


0
 
LVL 2

Expert Comment

by:jasonholland
ID: 10695007
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
0
 
LVL 1

Author Comment

by:pak_slm
ID: 10701841
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.

   
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question