返回列表 上一主題 發帖

請教各位先進多個OptionButton設定

請教各位先進多個OptionButton設定

我的程式要寫成使用OptionButton做選項:
在frame5中有5個OptionButton,選擇了之後接下來會到frame28 又會有2個OptionButton做選擇
程式如下:
第一組OptionButton
'------------------------------
flg = False
i = 1
For Each opt1 In Frame5.Controls
    If opt1.Value = True Then
        flg = True
        C_Index = opt1.Caption
        Exit For
    End If
    If i = 6 And flg = False Then
        mybtn = MsgBox(mymsg5, vbExclamation, mytitle)
        Exit Sub
    End If
i = i + 1
Next
'---------------------
中間有其他程式
'---------------------
第二組OptionButton

flg = False
iE = 1
For Each opt2 In Frame28.Controls
    If opt2.Value = True Then   '-----------------------執行到這一行卻顯示:執行階段錯誤 '438'  物件不支援此屬性或方法
        flg = True                                                                              請問我該如何改?
        PR_Index = opt2.Caption
        Exit For
    End If

    If iE = 2 And flg = False Then
        mybtn = MsgBox(mymsg6, vbExclamation, mytitle)
        Exit Sub
    End If
iE = iE + 1
Next

回復 3# sunnyso

這一招真是妙阿~高招
謝啦

TOP

回復 2# stillfish00


加入fish00 大大的條件式後發現
For Each opt2 In Frame28.Controls會從OptionButton11開始檢查
而我的OptionButton11~16是在frame5中, OptionButton17~18是在frame28中
所以當我要check frame28中的OptionButton時程式會先從OptionButton11,12,13.....,17,18檢查
當我的Userform裡有多個frame含有OptionButton時該如何避免程式每次都由第一個(OptionButton11)開始檢查?
如何指定程式由OptionButton17開始檢查?

TOP

        靜思自在 : 【時日莫空過】一個人在世間做了多少事,就等於壽命有多長。因此必須與時間競爭,切莫使時日空過。
返回列表 上一主題