Sort by Field Button

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

Guest

I'd like to create a button that sorts my form by a selected field. Can
someone help?
 
I'd like to create a button that sorts my form by a selected field. Can
someone help?

Are not the built-in Sort (A-Z, Z-A) tool buttons not enough?

Code a command button click event:
Me.OrderBy = Screen.PreviousControl.Name & " Asc"
Me.OrderByOn = True
 
Christian said:
I'd like to create a button that sorts my form by a selected field. Can
someone help?

Use the button's Click event procedure:

Me.OrderBy = "field name"
Me.OrderByOn = True
 
OK, is there a way to do it so that it uses the field's current value instead
of typing a new one?

Also, I'd like to place my button on another form (a toolbar so to speak).
How do I code it to reference the main form when the button is clicked. I
tried using setfocus but that doesn't work.
 
I think Fred has the right idea.

Besides, how would the code know which form to use?

If it's the same form all the time, then you could use:

With Forms![name of the form]
.OrderBy = .ActiveControl.ControlSource
.OrderByOn = True
End With
 

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

Back
Top