Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 3rd, 2006, 12:19 PM
Registered User
 
Join Date: Nov 2006
Location: , , .
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

Reply With Quote
  #2 (permalink)  
Old November 6th, 2006, 12:15 PM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 03:11 PM.


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