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 November 3rd, 2006, 12:19 PM
Registered User
 
Join Date: Nov 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Assigning Command Button to Query

I have made a query for each column in my table in order to sort by ascending order. I want to assign this Query to a column heading button on my form. What is the code, or how do I go about assiging this query to this button so every time it is clicked the data is sorted according to what that query says. This would be similar to sorting your e-mail account by clicking the header and it changing the order of mail by ascending order.

I am new at this, so if you could please include the code as well that would be very helpful.

list box = listbox73
command button = command43
query name = events location, tied to the events table

 
Old November 6th, 2006, 12:15 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Hiya,

   Here is what I did: I created a table with thrww columns, ID, Alpha, and Number. I set these values:

ID Alpha Number
1 A 3
2 B 2
3 C 1

Then I created a query that pulled all the fields in this table sorted by Alpha ASC, which sounds like what you did. Query was called "a"

Then I created a form basedon the table, made it a continuous form, and put the Alpha and Number fields in columns, and then put a button at the header over Alpha. I used this code on the Alpha button:

[Forms]![afrm].[RecordSource] = "a"

This changed the recordsource for the form to the query called a where the alpha column was sorted ascending.

I then used this code on the button over the Number column:

[Forms]![afrm].[RecordSource] = "SELECT * FROM Table1 ORDER BY [Num] ASC;"

So this does the same thing without having to call an external query, and did the same thing, it order the number column ASC.

Does this do what you want?



mmcdonal





Similar Threads
Thread Thread Starter Forum Replies Last Post
Assigning a toolbar button to open public folder Arsi BOOK: Professional Outlook 2007 Programming ISBN: 978-0-470-04994-5 2 December 13th, 2007 05:08 PM
Assigning variable value from a radio button cybersnac VB How-To 0 February 14th, 2007 03:57 PM
Command Button Question eoghang Excel VBA 2 September 25th, 2006 08:33 PM
Assigning Context.Items Value To SQL Query arsicles ASP.NET 1.0 and 1.1 Basics 1 April 20th, 2006 01:45 PM
Assigning a value to a Radio Button List acorbo ASP.NET 1.0 and 1.1 Professional 3 June 27th, 2004 12:39 AM





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