2011/01/15

access2010 DoCmd.SetFilter/DoCmd.SetOrderBy

地味だけど、access2010で追加されたDoCmdオブジェクトのメソッド。
ちょっとコードがすっきりするのと、サブフォーム/サブレポートに対する実行が便利なくらい。
あとは、フィルター設定時/フィルター実行時イベントを使えるようになる。使ったことないけど。


Option Compare Database
Option Explicit

Private Sub cmdClearFilterOrder_Click()
    Me.subform_form1.SetFocus
    DoCmd.RunCommand acCmdRemoveFilterSort
End Sub

Private Sub cmdSetFilter_Click()
    DoCmd.SetFilter , "ID > 3", "subform_form1"
End Sub

Private Sub cmdSetOrderby_Click()
    DoCmd.SetOrderBy "ID desc", "subform_form1"
End Sub
Option Compare Database
Option Explicit

Private Sub cmdClearFilterOrder_Click()
    DoCmd.RunCommand acCmdRemoveFilterSort
End Sub

Private Sub cmdSetFilter_Click()
    DoCmd.SetFilter , "ID > 3"
End Sub

Private Sub cmdFilterOn_Click()
    Me.Filter = "ID >3"
    Me.FilterOn = True
End Sub

Private Sub cmdOrderBy_Click()
    Me.OrderBy = "ID desc"
    Me.OrderByOn = True
End Sub

Private Sub cmdSetOrderby_Click()
    DoCmd.SetOrderBy "ID desc"
End Sub

Private Sub Form_ApplyFilter(Cancel As Integer, ApplyType As Integer)
    Debug.Print "ApplyFilter:" & ApplyType
End Sub

Private Sub Form_Filter(Cancel As Integer, FilterType As Integer)
    Debug.Print "Filter" & FilterType
End Sub

0 件のコメント: