May be easy, may be hard..
I'm creating a form in Excel 97 (my first in Excel, so please bear with me.. I'm used to Access ), which includes the following code behind a Userform:
(NOTES
frameCatSelection is a frame group, with two option buttons, and two labels. Each option button has an associated "Caption" property, set to the option description.
--- Begin Code ---
Private Function GetFrameGroupValue(frameGroup As Frame) As String
On Error GoTo Err_GetFrameGroupValue
Dim ctl As Control
GetFrameGroupValue = "'"
For Each ctl In frameGroup.Controls
If TypeOf ctl Is OptionButton Then
If ctl.Value = True Then
GetFrameGroupValue = ctl.Caption
Exit For
End If
End If
Next ctl
Exit_GetFrameGroupValue:
Set ctl = Nothing
Exit Function
Err_GetFrameGroupValue:
MsgBox Err.Description, , "GetFrameGroupValue: " & Err.Number
Resume Exit_GetFrameGroupValue
End Function
Private Sub frameCatSelection_Exit(ByVal Cancel As MSForms.ReturnBoolean)
On Error GoTo Err_frameCatSelection_Exit
Worksheets("(Hidden Sheet)".Range("C27".Value = _
GetFrameGroupValue(frameCatSelection)
Exit_frameCatSelection_Exit:
Exit Sub
Err_frameCatSelection_Exit:
MsgBox Err.Description, , "frameCatSelection_Exit: " & Err.Number
Resume Exit_frameCatSelection_Exit
End Sub
--- End Code ---
I started running into problems with this code (where the function apparently returns nothing), so I stepped through it, watching the expressions "frameGroup" and "ctl" in the "GetFrameGroupValue" function.
frameGroup appears to pass correctly. However, when it starts looping through controls, the first control, according to the Watch window, is a control of type Control/OptionButton. But the "TypeOf" condition fails. Why??? What should I be doing instead?
Thanks!!
I'm creating a form in Excel 97 (my first in Excel, so please bear with me.. I'm used to Access ), which includes the following code behind a Userform:
(NOTES
frameCatSelection is a frame group, with two option buttons, and two labels. Each option button has an associated "Caption" property, set to the option description.
--- Begin Code ---
Private Function GetFrameGroupValue(frameGroup As Frame) As String
On Error GoTo Err_GetFrameGroupValue
Dim ctl As Control
GetFrameGroupValue = "'"
For Each ctl In frameGroup.Controls
If TypeOf ctl Is OptionButton Then
If ctl.Value = True Then
GetFrameGroupValue = ctl.Caption
Exit For
End If
End If
Next ctl
Exit_GetFrameGroupValue:
Set ctl = Nothing
Exit Function
Err_GetFrameGroupValue:
MsgBox Err.Description, , "GetFrameGroupValue: " & Err.Number
Resume Exit_GetFrameGroupValue
End Function
Private Sub frameCatSelection_Exit(ByVal Cancel As MSForms.ReturnBoolean)
On Error GoTo Err_frameCatSelection_Exit
Worksheets("(Hidden Sheet)".Range("C27".Value = _
GetFrameGroupValue(frameCatSelection)
Exit_frameCatSelection_Exit:
Exit Sub
Err_frameCatSelection_Exit:
MsgBox Err.Description, , "frameCatSelection_Exit: " & Err.Number
Resume Exit_frameCatSelection_Exit
End Sub
--- End Code ---
I started running into problems with this code (where the function apparently returns nothing), so I stepped through it, watching the expressions "frameGroup" and "ctl" in the "GetFrameGroupValue" function.
frameGroup appears to pass correctly. However, when it starts looping through controls, the first control, according to the Watch window, is a control of type Control/OptionButton. But the "TypeOf" condition fails. Why??? What should I be doing instead?
Thanks!!