[AccessD] Problem with OrderBy function

Bob Gajewski rbgajewski at adelphia.net
Sun May 18 12:01:21 CDT 2008


Dear Friends

Once again, I find myself prevailing upon you to help me solve what should
be an easy problem.

I have a table (tblAgencies) which has an AutoNumber primary key and an
AgencyName index (ascending).

On my Form_Open (single form), I automatically apply a filter to show only
those records that have a Yes/No field (AgencyMutualAidFlag) equal to true.
On the form, there are two command buttons - one to show the filtered list
(cmdApplyFilter) and one to show all records (cmdShowAllRecords).

My problem is that when the form opens, the filtered recordset shows in
proper order - alphabetically by AgencyName. However, clicking on
cmdShowAllRecords returns the entire recordset but in AutoNumber order; not
by name. How do I add the OrderBy code to the command button code to ensure
that the records will ALWAYS be in AgencyName order? BTW, clicking on
cmdApplyFilter does return the filtered recordset in alphabetical order.

TIA,
Bob Gajewski


-----------------------------------------------------
Private Sub Form_Open(Cancel As Integer)
Call cmdApplyFilter_Click
End Sub
-----------------------------------------------------
Private Sub cmdApplyFilter_Click()
On Error GoTo Err_cmdApplyFilter_Click

    DoCmd.ApplyFilter , "AgencyMutualAidFlag = True"

Exit_cmdApplyFilter_Click:
    Exit Sub

Err_cmdApplyFilter_Click:
    MsgBox Err.Description
    Resume Exit_cmdApplyFilter_Click
    
End Sub
-----------------------------------------------------
Private Sub cmdShowAllRecords_Click()
On Error GoTo Err_cmdShowAllRecords_Click

    DoCmd.ShowAllRecords

Exit_cmdShowAllRecords_Click:
    Exit Sub

Err_cmdShowAllRecords_Click:
    MsgBox Err.Description
    Resume Exit_cmdShowAllRecords_Click
    
End Sub
-----------------------------------------------------




More information about the AccessD mailing list