用代码获取选定列的名称,我们使用Me.ActiveControl.Name
如数据表窗体加下面程序可以点击列表头进行排序:
Private Sub Form_Click()
On Error Resume Next
If Me.SelWidth > 1 Then Exit Sub
If Me.OrderBy = Me.ActiveControl.Name Then
Me.OrderBy =
Me.ActiveControl.Name & " DESC"
Else
Me.OrderBy =
Me.ActiveControl.Name
End If
Me.OrderByOn =
True
End Sub