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

"TypeOf" keyword seemingly not working

Status
Not open for further replies.

Katerine

Programmer
Mar 9, 2001
234
US
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!!
 
Never mind.. found it! :)

(in a rather odd place.. MS Knowledgebase article Q166933, which at first glance doesn't appear to have anything to do with the issue above..)

In case anybody's curious, the problem was fixed when I changed "OptionButton" to "MsForms.OptionButton". Apparently until that point, Excel thought I was referring to Excel's OptionButton control type.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top