A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Command Button to Sort and Filter by Selection



 
 
Thread Tools Display Modes
  #1  
Old February 2nd, 2010, 08:49 PM posted to microsoft.public.access.forms
areker
external usenet poster
 
Posts: 4
Default Command Button to Sort and Filter by Selection

Is it possible to create a command button on a form that will allow you to
sort records or to use the Filter by Selction option? They are not choices I
can select while using the wizard or the macro builder. However, both of
these would be extremely useful as I'm building a database for someone who
has never used a database before and isn't all that comfortable with
computers in general.

I am using Access 2003 and I am NOT familiar with Access Visual Basic, Java
or building macros from scratch. I'm sure there is a way to use these tools
to create what I want, but I don't know how to do it. Help?
  #2  
Old February 2nd, 2010, 10:11 PM posted to microsoft.public.access.forms
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Command Button to Sort and Filter by Selection

On Tue, 2 Feb 2010 12:49:01 -0800, areker
wrote:

Is it possible to create a command button on a form that will allow you to
sort records or to use the Filter by Selction option? They are not choices I
can select while using the wizard or the macro builder. However, both of
these would be extremely useful as I'm building a database for someone who
has never used a database before and isn't all that comfortable with
computers in general.

I am using Access 2003 and I am NOT familiar with Access Visual Basic, Java
or building macros from scratch. I'm sure there is a way to use these tools
to create what I want, but I don't know how to do it. Help?


The button would in fact use VBA (Visual Basic for Applications) within
Access.

The exact code would depend on your table structure and what it is that you
want to do. If you're going to do sorting or filtering, you must somehow
determine which fields to sort by and/or to search! If you could describe your
table structure (relevant fieldnames and datatypes), and a bit more about just
what you want this button to do, someone should be able to help... but to have
"Click this button to sort the data in the way I'm thinking of" requires the
telepathic interface, which won't be out until the release of Access
20mmfchokesputter

--

John W. Vinson [MVP]
  #3  
Old February 3rd, 2010, 07:54 PM posted to microsoft.public.access.forms
areker
external usenet poster
 
Posts: 4
Default Command Button to Sort and Filter by Selection


Thank you for replying to my Access Database question. I can't attach it
here, but I have a printscreen of the fields and datatypes I'm working with
in the table so far. I can email this to you or anyone else who might have
an answer.

Maybe what I am asking for isn't possible, I don't know. I would like for
her to be able to either sort or filter-by-selection (a separate command
button for each) not based so much on telepathy *smile* but on whatever field
she places her cursor in. This is how it works if you're using the menu
buttons across the top. If you're creating the command button with VBA code,
can you ask it to choose the appropriate field to sort or filter on based
solely on where the cursor is located, or are you limited to building the
command button using only one specific pre-determined field?


  #4  
Old February 3rd, 2010, 10:03 PM posted to microsoft.public.access.forms
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Command Button to Sort and Filter by Selection

On Wed, 3 Feb 2010 11:54:01 -0800, areker
wrote:


Thank you for replying to my Access Database question. I can't attach it
here, but I have a printscreen of the fields and datatypes I'm working with
in the table so far. I can email this to you or anyone else who might have
an answer.

Maybe what I am asking for isn't possible, I don't know. I would like for
her to be able to either sort or filter-by-selection (a separate command
button for each) not based so much on telepathy *smile* but on whatever field
she places her cursor in. This is how it works if you're using the menu
buttons across the top. If you're creating the command button with VBA code,
can you ask it to choose the appropriate field to sort or filter on based
solely on where the cursor is located, or are you limited to building the
command button using only one specific pre-determined field?


Well, the problem is that when you click a button on a control... *that button
has the focus*. You can use the Screen.PreviousControl method to see which
control previously had the focus. I'm imagining code like:

Private Sub cmdSort_Click()
Dim strControlsource As String
strControlsource = Screen.PreviousControl.ControlSource
Me.OrderBy = strControlsource
Me.OrderByOn = True


However, this will need some fairly elaborate error checking: check for
Err.Number = 2483 (there was no previous control), or other error numbers (if
the control source is an expression or something other than a fieldname, or if
the previous control was some object which doesn't HAVE a controlsource).

Good luck!
--

John W. Vinson [MVP]
 




Thread Tools
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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 07:19 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.