Use command button to sort records on a form

P

paulevans82

I have a form frmProgramEnrol based on qryProgramEnrol which displays
enrolments in a professional development course.

I would like to use command buttons in the footer to sort the records (I
will have three buttons, Sort by Name, Sort by Date, Sort by Status).

I used the following code:

Private Sub cmdSortName_Click()
Me.OrderBy = "[Person]"
Me.OrderByOn = True
End Sub

But when I click the button, I get the message
"The expression On Click you entered as the event property setting produced
the following error: Invalid outside procedure".

I'm pretty sure I'm missing something quite straightforward here. I would
appreciate your help
 
P

paulevans82

OK I fixed it - it wasn't a problem with what I was trying to do, it was that
I had a stray line of code elsewhere in the database
 
W

Wayne-I-M

Hi

Another way of doing this and you can use it on all the control on a
continous form would be to add a label for each "column" (control) on the
form.
So If you had controls with 1st name 2ndname dateofbirth etc
you would add a lable to the form header above each column

Put this on click of each label

Private Sub LabelName_Click()
Me.OrderBy = "[ControlName]"
Me.OrderByOn = True
End Sub

Change the LableName and ControlName to what the really are

Users like these as they are easy to understand and I use them as they
remove the need to add another button to a form - I try to keep the forms
un-cluttered
 

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