Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Order by button

Status
Not open for further replies.

rainford

Programmer
Jan 21, 2002
12
CA
I am tring to put a order by button that allows the user to order the records in a continous form by clicking on the button while they are on the field that they want to order the records by
My form has records source as a query(name query2) as follows

SELECT EMPCODE, FORMNUMBER, PROJECT
FROM ACTIVITY
WHERE (((ACTIVITY.EMPCODE)=[CurrentUser])
ORDER BY [Forms]![activitysub2]![ordby];

In the order by button I have the code

ordby = "FORMNUMBER"
Form.Refresh
Form.Requery

I don't know how to get the current field yet so I have hard coded ordby field to see if it will work. The order of the records does not change. Does anybody know what is wrong
 
First off - what's wrong is that as soon as you click the button the command button itself is the CurrentControl - not the textbox that you've just left.

I assume that the reason you're not using the Sort button on the toolbar is that you've disabled all toolbars. If not - then the Sort button will do all you need, you don't need a button on the form.


One way round the problem might be a Sort button beside each field that the user is to have the facility to sort by and then customise the code in each button like:-

Private Sub cmdSortProject()
Me!RecordSource = "SELECT EMPCODE, FORMNUMBER, PROJECT
FROM ACTIVITY
WHERE (((ACTIVITY.EMPCODE)=[CurrentUser])
ORDER BY PROJECT;"
End Sub




'ope-that-'elps.

G LS
 
Yes I have disabled the toolbar.How do write the code to execute the Sort button on the toolbar
 
If you've disabled the tool bar then you've disabled the toolbar - EOS.

You'll have to resort to the multi button solution above.

( Or create a custom tool bar that just has the Sort tool on it and enable that toolbar only.


G LS
 
How do you create a custom toolbar with sort and find only
 
In Form design view ( amongst other ) Right click on the toolbar & choose Customise ...

On the toolbars tab click on New ...
and name the new toolbar and watch the screen carefully to see there the little square box is dumped.

Change to the Commands tab of the dialog box and go to the Records category and drag the two sort tools onto your new toolbar ( The toolbar will expand to take each one as you drag it.)
Change category to Edit and drag the find tool onto the toolbar

Close dialog box and dock it onto an edge somewhere.

Then in the Form Design window property dialog box select the ToolBar parameter and change it to show the newly designed toolbar.

Save the Form.


QED.


G LS
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top