jwcolby
jwcolby at colbyconsulting.com
Fri Dec 7 10:54:03 CST 2007
Arthur,
In general I try to dissuade people from doing that for the simple reason
that the name of the function is not easily findable. Joe Six-pack searches
for SortByColumn in his code window, and (not understanding what it does)
not finding it referenced anywhere decides that can be safely deleted. Only
when the user actually clicks on a control that references that function
will the problem be discovered. No compile error because the control
property references a non-existent function. BAD!
Sometimes the best ideas have side effects that make it not such a good
idea.
At least if a control scanner is setting the property programmatically, the
name of the function will be found and this error avoided.
I do like your sort by column thingy though. Done at the framework level
that one will be a keeper.
John W. Colby
Colby Consulting
www.ColbyConsulting.com
-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Arthur Fuller
Sent: Friday, December 07, 2007 11:35 AM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] events question
I think the previous explanation is appropriate. I use that approach often.
For example, in a continuous form I define double-click as Sort, and another
double-click as Sort Descending. I have a function just as outlined
previously (in my case called SortByColumn()), and in the double-click
property I just type this:
<code>
=SortByColumn([Form])
</code>
In case anyone's interested, the code for said function is:
<code>
Public Function SortByColumn(f As Form)
Dim ctlCurrentControl As Control
Dim strControlName As String
Set ctlCurrentControl = Screen.ActiveControl
strControlName = ctlCurrentControl.Name
Debug.Print strControlName
Debug.Print f.OrderBy
'08-Sep-01
'line changed to support subform invocation 'ActiveForm refers to the master
form, not the subform
' If Screen.ActiveForm.OrderBy = vbNullString Then
If f.OrderBy = vbNullString Then
DoCmd.RunCommand acCmdSortAscending
' ElseIf Right(Screen.ActiveForm.OrderBy, 4) = "Desc" Then
ElseIf Right(f.OrderBy, 4) = "Desc" Then
DoCmd.RunCommand acCmdSortAscending
Else
DoCmd.RunCommand acCmdSortDescending
End If
Set ctlCurrentControl = Nothing
'DoCmd.RunCommand acCmdSortAscending 'or Descending
End Function
</code>
hth,
Arthur