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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form->frame->options help

Status
Not open for further replies.

FrankX

Programmer
Dec 28, 2001
14
US
Hi,
I'm pretty new to VBA. I have created a form (in Access) called frmMain. on it I have a frame called fraDays. In this frame I have 5 option buttons. I want to find which is selected and select a string based on that.
I have declared and set the form:
Dim frmMain As Form
Set frmMain = Forms("frmMain") Set frmMain = Forms("frmMain")

but I am unable as yet to work out how to access the frame or, when I do, tell which option is selected. could someone please help (my head is hurting)
Thanx
FrankX
 
Hi,
Here's a way to find which OptionButton has been selected within a frame...
Code:
    With UserForm1.Frame1
        For Each Control In .Controls
            With Control
                If .Value = True Then
                    MsgBox .Name
                End If
            End With
        Next
    End With
Skip,
metzgsk@voughtaircraft.com
 
You can make the design a bit more general by using the Tag Property as follows...
Code:
'design the form so that the Tag Property is set to type of control you are inserting
'then you can make decisions based on the type of control.
'this example has OptionButtons and CheckBoxes inside Frame1
    With UserForm1.Frame1
        For Each Control In .Controls
            With Control
                Select Case .Tag
                    Case "OptionButton"
                        If .Value = True Then
                            MsgBox .Name
                        End If
                    Case "CheckBox"
                        If .Value = True Then
                            MsgBox .Name
                        End If
                End Select
            End With
        Next
    End With
Skip,
metzgsk@voughtaircraft.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top