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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RunCommand SortAscending error

Status
Not open for further replies.

bartoki

IS-IT--Management
Oct 6, 2003
22
0
0
US
In trying to create a database that will be used by someone who knows nothing about access, I want to place a sort button on my forms where when the user has their cursor in a field, this button will sort that field accordingly.

Currently I have a macro that simply runs the command SortAscending. When I try this I get an "Action Failed" error and it tells me "this command or action is not available." This error happens regardless of which field my cursor is in. I believe there is an easy fix to this....what is it?

Thanks!
 
You need to add a command to your macro above SortAscending.
Select GoTo Control as the Action, and a Control Name (Field) that you want to Sort on on your form as the Control Name.

Basically, while your Button has the focus, you can't sort.

Bill
 
I thought it would be something like that. But if I have a dozen fields on this form, then I will need two dozen buttons (ascending, descending). Is there anyway to tell it "the current field" or something similar so it will use the field my cursor is in?

Thanks Bill.
 
As far as I know you can only do this in code and this will not work if your controls are on a Sub Form and the button is on a Main Form:

In the On Click event of the button:

Screen.PreviousControl.SetFocus
DoCmd.RunCommand acCmdSortAscending

That's the best I can suggest.

Bill
 
bartoki,

You can put a new, unbound combo-box on your form. Its
rowsource can be the names of your fields. In its After
Update event you can:

Code:
Me.YourForm.RecordSource = "Select * From YourTable " & _
"Order By " & Me.YourCombo & ";"
Me.ReQuery

That way, whenever you select a field in the combo, it
will requery and sort on the field in the combo-box.

Wayne
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top