Sorting via vba code

P

peruvian99

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
 
C

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.

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
 
M

Marshall Barton

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top