Sorting via vba code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have this form which I want to be able sort by clicking on a command button.

For instance if the button is above the "stocks" field 9textbox) - clicking
on the command button right above it would sort it descending. --- clicking
on the command button above the field "Profits" -- it would be sort it
descending by the amount.

I can currently do this by clicking the sort button in the toolbar, but I
want to do this via vba cide.

JPierre
 
peruvian99 said:
I have this form which I want to be able sort by clicking on a command
button.

For instance if the button is above the "stocks" field 9textbox) -
clicking
on the command button right above it would sort it descending. ---
clicking
on the command button above the field "Profits" -- it would be sort it
descending by the amount.

I can currently do this by clicking the sort button in the toolbar, but I
want to do this via vba cide.

JPierre

What you would need to do is, in the button's Click event modify the form's
OrderBy property to include the proper sorting. Be sure to also set
OrderByOn to True when you do so. Look in Access help for OrderBy and
OrderByOn.

You could also accomplish this by changing the form's RecordSource property
directly, if you wished.

Carl Rapson
 
peruvian99 said:
I have this form which I want to be able sort by clicking on a command button.

For instance if the button is above the "stocks" field 9textbox) - clicking
on the command button right above it would sort it descending. --- clicking
on the command button above the field "Profits" -- it would be sort it
descending by the amount.


Use code in each button's Click event procedure:

Me.OrderBy = "[Stocks] DESC"
Me.OrderByOn = True
 
Back
Top