|
<つづき3>
(4) フォームのクラスモジュール
------------------------------------------------------------------------------------------------
フォーム[FrmMain]
------------------------------------------------------------------------------------------------
Option Compare Database
Option Explicit
'-----------------------------------------------------------------------------------------------
'プロパティ値保存用オブジェクト変数
'-----------------------------------------------------------------------------------------------
Private mAutoFilterSetting As dbsProject1.ClsAutoFilterSetting
'-----------------------------------------------------------------------------------------------
'プロパティの値を取得 - オートフィルタ設定
'-----------------------------------------------------------------------------------------------
Public Property Get AutoFilterSetting() As dbsProject1.ClsAutoFilterSetting
Set AutoFilterSetting = mAutoFilterSetting
End Property
'-----------------------------------------------------------------------------------------------
'プロパティに値を設定 - オートフィルタ設定
'-----------------------------------------------------------------------------------------------
Public Property Set AutoFilterSetting(ByVal pAutoFilterSetting As dbsProject1.ClsAutoFilterSetting)
Set mAutoFilterSetting = pAutoFilterSetting
End Property
'-----------------------------------------------------------------------------------------------
'フォーム - 読み込み時イベントプロシージャ
'-----------------------------------------------------------------------------------------------
Private Sub Form_Load()
Set mAutoFilterSetting = New dbsProject1.ClsAutoFilterSetting
Me.AutoFilterSetting.PropertyInitialize _
MainForm:=Me _
, DisplayForm:=Me.SfmFrmSub.Form _
, rstRecordSource:=Me.SfmFrmSub.Form.RecordsetClone
End Sub
'-----------------------------------------------------------------------------------------------
'フォーム - 閉じる時イベントプロシージャ
'-----------------------------------------------------------------------------------------------
Private Sub Form_Close()
Set mAutoFilterSetting = Nothing
End Sub
'-----------------------------------------------------------------------------------------------
'条件指定用コントロールのフォーカス取得後
'-----------------------------------------------------------------------------------------------
Private Function EvtFilterControl_OnGotFocus() As Long
Me.AutoFilterSetting.EvtFilterControlGotFocus FilterControl:=Me.ActiveControl
End Function
'-----------------------------------------------------------------------------------------------
'条件指定用コントロールの更新後処理
'-----------------------------------------------------------------------------------------------
Private Function EvtFilterControl_AfterUpdate() As Long
Me.AutoFilterSetting.EvtFilterControlAfterUpdate FilterControl:=Me.ActiveControl
End Function
------------------------------------------------------------------------------------------------
フォーム[FrmAutoFilterOption]
------------------------------------------------------------------------------------------------
Option Compare Database
Option Explicit
'-----------------------------------------------------------------------------------------------
'プロパティ値保存用定数
'-----------------------------------------------------------------------------------------------
Private Const cFilterCompareRowSourceType As String = "Value List"
Private Const cFilterCompareRowSource As String _
= ";;" _
& "と等しい;=;" _
& "と等しくない;<>;"
'-----------------------------------------------------------------------------------------------
'プロパティ値保存用オブジェクト変数
'-----------------------------------------------------------------------------------------------
Private mAutoFilterSetting As dbsProject1.ClsAutoFilterSetting
'-----------------------------------------------------------------------------------------------
'プロパティの値を取得 - オートフィルタ設定
'-----------------------------------------------------------------------------------------------
Public Property Get AutoFilterSetting() As dbsProject1.ClsAutoFilterSetting
Set AutoFilterSetting = mAutoFilterSetting
End Property
'-----------------------------------------------------------------------------------------------
'プロパティに値を設定 - オートフィルタ設定
'-----------------------------------------------------------------------------------------------
Public Property Set AutoFilterSetting(ByVal pAutoFilterSetting As dbsProject1.ClsAutoFilterSetting)
Set mAutoFilterSetting = pAutoFilterSetting
End Property
'-----------------------------------------------------------------------------------------------
'フォーム - 開く時イベントプロシージャ
'-----------------------------------------------------------------------------------------------
Private Sub Form_Open(Cancel As Integer)
'他のフォームから呼び出されていない場合
If IsNull(Me.OpenArgs) Then
Let Cancel = True
End If
End Sub
'-----------------------------------------------------------------------------------------------
'フォーム - 読み込み時イベントプロシージャ
'-----------------------------------------------------------------------------------------------
Private Sub Form_Load()
'オブジェクト変数
Dim clsElement As dbsProject1.ClsAutoFilterControlSetting
'初期設定
Set mAutoFilterSetting = Application.Forms(Me.OpenArgs).AutoFilterSetting
Set clsElement = Me.AutoFilterSetting.Items(Index:=Me.AutoFilterSetting.CurrentFilterControl.Name)
'オプショングループのラベルに対象フィールド名を設定
Let Me.FraFilterOption.Controls(0).Caption = clsElement.FieldName
'演算子の設定
Select Case clsElement.FilterOperator
'設定が保存されている場合
Case Me.OptAnd.OptionValue, Me.OptOr.OptionValue
Let Me.FraFilterOption.Value = clsElement.FilterOperator
'そうでない場合 - ANDに設定
Case Else
Let Me.FraFilterOption.Value = Me.OptAnd.OptionValue
End Select
'値(条件1)指定用コンボボックスの設定
Let Me.CmbValues1.RowSource _
= Me.AutoFilterSetting.GetRowSource( _
FilterControlName:=clsElement.FilterControlName, AddListOption:=False)
If Not (IsNull(clsElement.FilterValues1)) Then
Let Me.CmbValues1.Value = clsElement.FilterValues1
End If
'値(条件2)指定用コンボボックスの値集合ソース(2)
Let Me.CmbValues2.RowSource _
= Me.AutoFilterSetting.GetRowSource( _
FilterControlName:=clsElement.FilterControlName, AddListOption:=False)
If Not (IsNull(clsElement.FilterValues2)) Then
Let Me.CmbValues2.Value = clsElement.FilterValues2
End If
'比較方法指定用コンボボックスの設定(1)
With Me.CmbCompare1
.ColumnCount = 2
.RowSourceType = cFilterCompareRowSourceType
.RowSource = cFilterCompareRowSource
.ColumnWidths = Format(.Width, "0\;") & "0;"
.Value = .ItemData(clsElement.FilterCompare1)
End With
'比較方法指定用コンボボックスの設定(1)
With Me.CmbCompare2
.ColumnCount = 2
.RowSourceType = cFilterCompareRowSourceType
.RowSource = cFilterCompareRowSource
.ColumnWidths = Format(.Width, "0\;") & "0;"
.Value = .ItemData(clsElement.FilterCompare2)
End With
'オブジェクト変数の解放
Set clsElement = Nothing
End Sub
'-----------------------------------------------------------------------------------------------
'フォーム - 閉じる時イベントプロシージャ
'-----------------------------------------------------------------------------------------------
Private Sub Form_Close()
Set mAutoFilterSetting = Nothing
End Sub
'-----------------------------------------------------------------------------------------------
'オプショングループ [条件] - 更新後処理イベントプロシージャ
'-----------------------------------------------------------------------------------------------
Private Sub FraFilterOption_AfterUpdate()
'演算子の設定を更新
With Me.AutoFilterSetting
.Item(.CurrentFilterControl.Name).FilterOperator = Me.FraFilterOption.Value
End With
End Sub
'-----------------------------------------------------------------------------------------------
'コンボボックス [値(条件1)] - 更新後処理イベントプロシージャ
'-----------------------------------------------------------------------------------------------
Private Sub CmbValues1_AfterUpdate()
'値(条件1)の設定を更新
With Me.AutoFilterSetting
.Item(.CurrentFilterControl.Name).FilterValues1 = Me.CmbValues1.Value
End With
End Sub
|
|