Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sorting a subform

Status
Not open for further replies.

rewdee

Programmer
Aug 17, 2001
295
0
0
US
Good Morning,

I have a form with a subform. In the subform, I'm putting a button in the header that allows the user to toggle between sort ascending and descending. The button works perfectly on the first click but will not allow access to do anything else. If you click another button (any button) you get the message "error 2486 -- you can't carry out this action at the present time".
Code:
==========================================================
Private Sub CmdSortEvent_Click()
    If Me.CmdSortEvent.Caption = "Events (a-z)" Then
        DoSort "txtevent_ID", acCmdSortAscending
        Me.CmdSortEvent.Caption = "Events (z-a)"
    Else
        DoSort "txtevent_ID", acCmdSortDescending
        Me.CmdSortEvent.Caption = "Events (a-z)"
    End If
End Sub

Private Sub DoSort(sCtrlName As String, lngSortMethod)
'generic procedure to do sort on a current recordset
    DoCmd.Hourglass True
    Screen.ActiveForm.AllowAdditions = False
    DoCmd.GoToControl sCtrlName
    DoCmd.RunCommand lngSortMethod
    DoCmd.Hourglass False
End Sub
==========================================================
Any ideas of why I'm getting this error or how to sort on a subform? I guess I could build a procedure that rebuilds the data source and ORDER BY based on which button is clicked but I thought this would be easier.

Thanks,
Rewdee
 
It's setting AllowAdditions to false but not resetting it to true. This won't allow you to add records.

To resort, you can set ORDER BY in your code and requery.
Me.OrderBy = &quot;<fieldname>&quot;/&quot;<fieldname> DESC&quot;
Me.Requery

You may not even have to requery, but I'm not sure about that.

As far as determining which way to sort, you can use 'if' or alternate command buttons. In the 'if' statement, just check for DESC and change whether that's there. To alternate buttons, change their 'Visible' and 'Enabled' properties. 'If' would be easier.
 
Hi.

Did you resolve this issue?

Error 2486 is a pain! So far I have seen it only in Access2000, and the line that crashes always starts
out: Docmd.

I believe that something triggers Access2000 to start a chunk of code, that runs either recursively or in an infinite loop.

gzep, SoF.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top