Subform Sorting Problem

G

Guest

I have a main form and a subform. The subform is a list of data displayed in
datasheet view. I want the user to be able to sort the data by any column in
the datasheet so on the main form have added a Sort button with the following
code on its Click Event:

Private Sub cmdSortA_Click()
Me.sfrmDetails.SetFocus
DoCmd.RunCommand (acCmdSortAscending)
End Sub

This works fine as long as the user clicks on a row before sorting. However,
if they click on the column heading first, not only does it not work, it also
seems to throw the subform into a state whereby they are unable to edit the
data. There is no error message generated and the situation is only resolved
by closing and re-opening the main form.

I need to either disable the column headings so that they cannot be clicked
on or detect that the heading has been selected and not run the sort code. I
am not sure if it is possible to do either of these things.

Any help appreciated.
 

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