Command Button to Sort and Filter by Selection

A

areker

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?
 
J

John W. Vinson

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>
 
A

areker

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?
 
J

John W. Vinson

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top