Created
July 30, 2012 04:46
-
-
Save hatena19/3204751 to your computer and use it in GitHub Desktop.
Access VBA オプショングループ上の選択されたコントロール名あるいはその標題を返す関数
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' *************************************** | |
' 関数名: SelectControlNameOnOptionGroup | |
' 目 的: オプショングループ上の選択されたコントロールの名前を返します。 | |
' 作成者: hatena | |
' 作成日: 2012/07/29 | |
' 戻り値: バリアント型(文字列) | |
' 引数の説明: | |
' Opt -> 必須です。対象となる「オプショングループ」オブジェクトを指定します。 | |
' 使用上の注意: 未選択(Null値または、存在しないオプション値)の場合はNullを返します。 | |
' 使用例: | |
' Msgbox Nz(SelectControlNameOnOptionGroup(Me.フレーム1),"選択されてません。") | |
' *************************************** | |
Public Function SelectControlNameOnOptionGroup(Opt As OptionGroup) As Variant | |
Dim Ctl As Control | |
SelectControlNameOnOptionGroup = Null | |
If IsNull(Opt.Value) Then Exit Function | |
For Each Ctl In Opt.Controls | |
If Ctl.ControlType <> acLabel Then | |
If Opt.Value = Ctl.OptionValue Then | |
SelectControlNameOnOptionGroup = Ctl.Name | |
Exit For | |
End If | |
End If | |
Next | |
End Function | |
' *************************************** | |
' 関数名: SelectControlCaptionOnOptionGroup | |
' 目 的: オプショングループ上の選択されたコントロールの標題または付属するラベルの標題を返します。 | |
' 作成者: hatena | |
' 作成日: 2012/07/29 | |
' 戻り値: バリアント型(文字列) | |
' 引数の説明: | |
' Opt -> 必須です。対象となる「オプショングループ」オブジェクトを指定します。 | |
' 使用上の注意: 未選択(Null値または、存在しないオプション値)の場合はNullを返します。 | |
' 使用例: | |
' Msgbox Nz(SelectControlCaptionOnOptionGroup(Me.フレーム1),"選択されてません。") | |
' *************************************** | |
Public Function SelectControlCaptionOnOptionGroup(Opt As OptionGroup) As Variant | |
Dim Ctl As Control | |
SelectControlCaptionOnOptionGroup = Null | |
If IsNull(Opt.Value) Then Exit Function | |
For Each Ctl In Opt.Controls | |
Select Case Ctl.ControlType | |
Case acCheckBox, acOptionButton | |
If Opt.Value = Ctl.OptionValue Then | |
If Ctl.Controls.Count = 0 Then | |
SelectControlCaptionOnOptionGroup = "" | |
Else | |
SelectControlCaptionOnOptionGroup = Ctl.Controls(0).Caption | |
End If | |
Exit For | |
End If | |
Case acToggleButton | |
If Opt.Value = Ctl.OptionValue Then | |
SelectControlCaptionOnOptionGroup = Ctl.Caption | |
Exit For | |
End If | |
End Select | |
Next | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment