472,789 Members | 1,317 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,789 software developers and data experts.

comand buttons not sorting after filtering form

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
2 2354
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Richard | last post by:
Hi, I have a form that take some time to load due to many comboboxes and at least 8 subforms. When I filter or sort the main form I get an error message and then Access shuts down. They ask if...
5
by: Axel | last post by:
An Access 2000 question Hi is is possible to have (as a subform) a continous form with 0..n buttons which have different images in each row. (Personally I would have preferred a button...
1
by: aintnorock | last post by:
I have a relatively simple relational database. One of my forms is based on a query with a 3 parameter sort: Status / Priority / Customer. When I open the form, the records are sorted properly. ...
5
by: LDD | last post by:
Hi Folks I'm trying to determine a way to handle paging, filtering and sorting in a datagrid. If I choose to filter and sort, I'd like to return a subset. If that resultset has more records...
10
by: Sjaakie | last post by:
Hi, I'm, what it turns out to be, fooling around with 3-tier design. At several websites people get really enthusiastic about using custom dataobjects instead of datasets/-tables. While trying to...
3
by: Harry Haller | last post by:
Hello, I want to implement a generic list which will be used to display 7 columns in a GridView. One should be able to sort, filter and page each of the 7 columns. Ideally the filter should be...
9
by: mosscliffe | last post by:
I am struggling to find a python example of the scenario - I have. I have a python script, which generates a page with a search button (actually an input field). The data from the above...
0
by: Yarik | last post by:
Hello, Here is a sample (and very simple) code that binds an Access 2003 form to a fabricated ADO recordset: ' Create recordset... Dim rs As ADODB.Recordset: Set rs = New ADODB.Recordset '...
2
by: Element | last post by:
I have a master form with a simple subform that displays line items in datasheet mode. Everything works fine, except that when the subform has the focus, the standard Access sorting and filtering...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.