Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 14th, 2008, 03:33 PM
Authorized User
 
Join Date: Oct 2006
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default Sorting By Different Fields On a Form

I have a form with 4 columns, and I would like to be able to sort on any column I choose.

I put a toggle above each column, and for each toggle I redefine the SQL to order by that field and save the query def. That part works .... but it will not refresh the view on the form to show me the resorted data.

If I close the form and reopen it it is sorted by the last column that I chose, so I know thats working.

If I click in a field and use that AZ icon on the access toolbar, then it sorts and refreshes on that column. But that icon won't visible neccesarily to the user.

But me.requery is not working. I am not using a cloned recordset.' How do I make the view show the new sort order?

Private Sub SetSQLBase()
SQLSort = "SELECT t_EmpCrewAssignment.CrewName, t_EmpCrewAssignment.Cr" _
& "ewID, t_EmpCrewAssignment.EmpName, t_EmpCrewAssignment.EmpI" _
& "D" & vbNewLine & "FROM t_EmpCrewAssignment" & vbNewLine
End Sub


Private Sub tglSortCrewID_Click()
UntoggleSortKeys ("tglSortCrewID")
SetSQLBase
SQLSort = SQLSort & "ORDER BY t_EmpCrewAssignment.CrewID;" & vbNewLine
CurrentDb.QueryDefs("q_EmpCrewAssignment").SQL = SQLSort
Me.Requery
End Sub
 
Old December 14th, 2008, 04:23 PM
Authorized User
 
Join Date: Oct 2006
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default Needed to reset the record source!

I stumbled into it!

Private Sub cmdSortCrewName_Click()
SetSQLBase
SQLSort = SQLSort & "ORDER BY t_EmpCrewAssignment.CrewName;" & vbNewLine
CurrentDb.QueryDefs("q_EmpCrewAssignment").SQL = SQLSort
Me.RecordSource = "q_EmpCrewAssignment" '<--this fixed it
'Me.Requery was not needed at all!!

End Sub

Thanks anyways!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Form Fields Terry J Daichendt JSP Basics 2 September 15th, 2008 05:53 PM
Sorting in a Form digby_dog Access 3 August 17th, 2007 03:32 PM
copy fields from Form to new form - openargs justabeginner Access VBA 1 February 4th, 2007 01:28 PM
how can i see the modifications in a form fields thomaz C# 1 September 7th, 2003 04:27 AM
session details & 2 fields sorting qwprince Classic ASP Databases 2 August 2nd, 2003 05:43 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.