473,320 Members | 1,870 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 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 2408
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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.