Command Button to Sort and Filter by Selection

  • Follow


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?
0
Reply Utf 2/2/2010 8:49:01 PM

On Tue, 2 Feb 2010 12:49:01 -0800, areker <areker@discussions.microsoft.com>
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
20<mmf><choke><sputter>

-- 

             John W. Vinson [MVP]
0
Reply John 2/2/2010 10:11:46 PM


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?     


0
Reply Utf 2/3/2010 7:54:01 PM

On Wed, 3 Feb 2010 11:54:01 -0800, areker <areker@discussions.microsoft.com>
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]
0
Reply John 2/3/2010 10:03:42 PM

3 Replies
1470 Views

(page loaded in 0.017 seconds)

Similiar Articles:
















7/23/2012 3:33:01 AM


Reply: