By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,561 Members | 3,221 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,561 IT Pros & Developers. It's quick & easy.

comand buttons not sorting after filtering form

P: n/a
Hi folks.

I have a form, frmHistory, which has 4 command buttons: Sort Title
(cmdSortTitle), Sort Name (cmdSortName), Due Today (cmdDueToday), and
Due List (cmdDueList).

Sort Title and Sort Name uses VBA code, and sorts the form either
ascending or descending, by title and by name respectively.

Due Today and Due List uses macros, and filters the form to display
records of books that are due on the current date and the entire list
of due books respectively.

The reason why I used command buttons to sort the form instead of
toggle buttons is that the toggle buttons would only go through a
"loop" once i.e. I can only click it twice to sort the form ascending
and descending, then it wouldn't work anymore.

The problem is that, while the sort buttons work fine, it doesn't work
once I used either one of or both of the filter buttons. Does anyone
know why? I have included the coding for the buttons below. Thanks for
your help.

'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''
Private Sub Form_Open(Cancel As Integer)

Me.OrderBy = ""
Me.OrderByOn = True

End Sub

'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''
Private Sub cmdSortTitle_Click()

Static x
x = x + 1
If x > 2 Then x = 1

Select Case x:
Case 1: Me.OrderBy = "Title"
Case 2: Me.OrderBy = "Title DESC"
End Select

End Sub

'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''
Private Sub cmdSortName_Click()

Static x
x = x + 1
If x > 2 Then x = 1

Select Case x:
Case 1: Me.OrderBy = "MemName"
Case 2: Me.OrderBy = "MemName DESC"
End Select

End Sub

'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''
cmdDueToday: OpenForm
Form Name: frmHistory
Where Condition: ([Return] Is Null) And ([Due]=Date())

cmdDueList: OpenForm
Form Name: frmHistory
Where Condition: ([Return] Is Null)

'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Not to dance around the issue, but I use two command buttons for this
procedure. I size them exactly the same and place one on top of the other.
I set the visible property of the descending button to false. Then use the
on click event of the buttons as follows. I didn't design the code and
can't remember where I got it so I can't give credit where it's due. Hope
it helps!

Private Sub cmdSortAscTitle_Click()
On Error GoTo cmdSortAscTitle_Click_Err

DoCmd.Echo False, "Sorting records ..."

Screen.ActiveForm.AllowAdditions = False
DoCmd.GoToControl "Title"
DoCmd.RunCommand acCmdSortAscending

Me![cmdSortDescTitle].Visible = True
Me![cmdSortDescTitle].SetFocus
Me![cmdSortAscTitle].Visible = False
DoCmd.Echo True, ""
Exit Sub

cmdSortAscTitle_Click_Exit:
DoCmd.GoToRecord , , acFirst
Exit Sub

cmdSortAscTitle_Click_Err:
Resume cmdSortAscTitle_Click_Exit

End Sub

Private Sub cmdSortDescTitle_Click()
On Error GoTo cmdSortDescTitle_Click_Err

DoCmd.Echo False, "Sorting records ..."

Screen.ActiveForm.AllowAdditions = False
DoCmd.GoToControl "Title"
DoCmd.RunCommand acCmdSortDescending

Me![cmdSortAscTitle].Visible = True
Me![cmdSortAscTitle].SetFocus
Me![cmdSortDescTitle].Visible = False
DoCmd.Echo True, ""
Exit Sub

cmdSortDescTitle_Click_Exit:
DoCmd.GoToRecord , , acFirst
Exit Sub

cmdSortDescTitle_Click_Err:
Resume cmdSortDescTitle_Click_Exit

End Sub
--
Reggie

www.smittysinet.com
----------
"Aravind" <so**********@hotmail.com> wrote in message
news:61**************************@posting.google.c om...
Hi folks.

I have a form, frmHistory, which has 4 command buttons: Sort Title
(cmdSortTitle), Sort Name (cmdSortName), Due Today (cmdDueToday), and
Due List (cmdDueList).

Sort Title and Sort Name uses VBA code, and sorts the form either
ascending or descending, by title and by name respectively.

Due Today and Due List uses macros, and filters the form to display
records of books that are due on the current date and the entire list
of due books respectively.

The reason why I used command buttons to sort the form instead of
toggle buttons is that the toggle buttons would only go through a
"loop" once i.e. I can only click it twice to sort the form ascending
and descending, then it wouldn't work anymore.

The problem is that, while the sort buttons work fine, it doesn't work
once I used either one of or both of the filter buttons. Does anyone
know why? I have included the coding for the buttons below. Thanks for
your help.

'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''
Private Sub Form_Open(Cancel As Integer)

Me.OrderBy = ""
Me.OrderByOn = True

End Sub

'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''
Private Sub cmdSortTitle_Click()

Static x
x = x + 1
If x > 2 Then x = 1

Select Case x:
Case 1: Me.OrderBy = "Title"
Case 2: Me.OrderBy = "Title DESC"
End Select

End Sub

'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''
Private Sub cmdSortName_Click()

Static x
x = x + 1
If x > 2 Then x = 1

Select Case x:
Case 1: Me.OrderBy = "MemName"
Case 2: Me.OrderBy = "MemName DESC"
End Select

End Sub

'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''
cmdDueToday: OpenForm
Form Name: frmHistory
Where Condition: ([Return] Is Null) And ([Due]=Date())

cmdDueList: OpenForm
Form Name: frmHistory
Where Condition: ([Return] Is Null)

'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''

Nov 13 '05 #2

P: n/a
so**********@hotmail.com (Aravind) wrote in
news:61**************************@posting.google.c om:
Hi folks.

I have a form, frmHistory, which has 4 command buttons: Sort
Title (cmdSortTitle), Sort Name (cmdSortName), Due Today
(cmdDueToday), and Due List (cmdDueList).

Sort Title and Sort Name uses VBA code, and sorts the form
either ascending or descending, by title and by name
respectively.

Due Today and Due List uses macros, and filters the form to
display records of books that are due on the current date and
the entire list of due books respectively.

The reason why I used command buttons to sort the form instead
of toggle buttons is that the toggle buttons would only go
through a "loop" once i.e. I can only click it twice to sort
the form ascending and descending, then it wouldn't work
anymore.

The problem is that, while the sort buttons work fine, it
doesn't work once I used either one of or both of the filter
buttons. Does anyone know why? I have included the coding for
the buttons below. Thanks for your help.
Just madd a Me.OrderByOn = true after setting the filter.
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''
'''''''' Private Sub Form_Open(Cancel As Integer)

Me.OrderBy = ""
Me.OrderByOn = True

End Sub

'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''
'''''''' Private Sub cmdSortTitle_Click()

Static x
x = x + 1
If x > 2 Then x = 1

Select Case x:
Case 1: Me.OrderBy = "Title"
Case 2: Me.OrderBy = "Title DESC"
End Select

End Sub

'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''
'''''''' Private Sub cmdSortName_Click()

Static x
x = x + 1
If x > 2 Then x = 1

Select Case x:
Case 1: Me.OrderBy = "MemName"
Case 2: Me.OrderBy = "MemName DESC"
End Select

End Sub

'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''
'''''''' cmdDueToday: OpenForm
Form Name: frmHistory
Where Condition: ([Return] Is Null) And
([Due]=Date())

cmdDueList: OpenForm
Form Name: frmHistory
Where Condition: ([Return] Is Null)

'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''
''''''''


Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.