By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,207 Members | 1,065 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,207 IT Pros & Developers. It's quick & easy.

Listbox Positioning

P: n/a
I want a listbox to position to a letter provided by the user.
Normally, when the user keys a letter, the listbox positions
automatically to the first entry starting with that letter in the
first column.

I want to allow the user to select the column to be searched.

For eaxample, assume a list box that looks like this:

____________________________
| Title | Author |
|----------|----------------|
| Oklahoma | Hammerstein, O |
| Hamlet | Shakespeare, W |
Nov 12 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
DFS
Mike,

No can do, using the default listbox behavior. Focus will always move to
the matching value in the 1st column.

You might be able to code something in the KeyPress event to move to the
entry in the 2nd column (I've never tried it).

Or you could create a combo box that lets the user choose from a predefined
list of sorting options, and update the listbox rowsource with a new
rowsource, ie:

control: comboBox
columns: 1
RowsourceType: ValueList
RowSource: Title then Author; Author then Title; Year then Title then Author

In the AfterUpdate event of the combobox, add code like this:

if me.comboBox = "Title then Author" then me.listBox.Rowsource = "SELECT
Title, Author FROM Tables ORDER BY Title, Author;"

elseif me.comboBox = "Author then Title" then me.listBox.Rowsource = "SELECT
Author, Title FROM Tables ORDER BY Author, Title;"

elseif me.comboBox = "Year then Title then Author" then me.listBox.Rowsource
= "SELECT PublicationYear, Title, Author FROM Tables ORDER BY
PublicationYear, Title, Author;"
endif

You'll have to futz around with column counts, widths, etc.

In the end, you'll probably be better off creating separate combo or list
boxes for each field you want to search.

"Mike Top" <mi******@rogers.com> wrote in message
news:ec**************************@posting.google.c om...
I want a listbox to position to a letter provided by the user.
Normally, when the user keys a letter, the listbox positions
automatically to the first entry starting with that letter in the
first column.

I want to allow the user to select the column to be searched.

For eaxample, assume a list box that looks like this:

____________________________
| Title | Author |
|----------|----------------|
| Oklahoma | Hammerstein, O |
| Hamlet | Shakespeare, W |
.
.

Now, assume the listbox is sorted on the second column (Author), but
the column sequence stays as is. If the user keys a "S", I want the
list to position on the second entry.

Nov 12 '05 #2

P: n/a
On 5 Jan 2004 19:39:11 -0800, mi******@rogers.com (Mike Top) wrote:

You "position a listbox" by setting the Value property.
I did this test by creating a new form in the Northwind sample
application. I set the Rowsource to:
SELECT [Employees].[EmployeeID], [Employees].[FirstName],
[Employees].[LastName] FROM Employees ORDER BY [LastName];
and the ColumnWidths to:
0";1";1"
Then it's just a matter of finding out which value to select:
Private Sub List0_KeyDown(KeyCode As Integer, Shift As Integer)
List0.Value = DLookup("EmployeeID", "Employees", "LastName LIKE '"
& Chr$(KeyCode) & "*'")
KeyCode = 0 ' Cancel the event (otherwise a FirstName would be
selected)
End Sub

Note that it would have been better if in the KeyDown event I had used
the exact same sql statement as RowSource is using. I leave that for
you to implement.

-Tom.
I want a listbox to position to a letter provided by the user.
Normally, when the user keys a letter, the listbox positions
automatically to the first entry starting with that letter in the
first column.

I want to allow the user to select the column to be searched.

For eaxample, assume a list box that looks like this:

____________________________
| Title | Author |
|----------|----------------|
| Oklahoma | Hammerstein, O |
| Hamlet | Shakespeare, W |
.
.

Now, assume the listbox is sorted on the second column (Author), but
the column sequence stays as is. If the user keys a "S", I want the
list to position on the second entry.


Nov 12 '05 #3

P: n/a
Hi, Mike:

You can add an option box with radio buttons, the options being sort by title
or sort by author; then the afterupdate of the option box changes the rowsource
of the listbox. Pretty simple to execute and gives the user the option to
search on either field.

HTH

Jan
I want a listbox to position to a letter provided by the user.
Normally, when the user keys a letter, the listbox positions
automatically to the first entry starting with that letter in the
first column.

I want to allow the user to select the column to be searched.

For eaxample, assume a list box that looks like this:

____________________________
| Title | Author |
|----------|----------------|
| Oklahoma | Hammerstein, O |
| Hamlet | Shakespeare, W |
.
.

Now, assume the listbox is sorted on the second column (Author), but
the column sequence stays as is. If the user keys a "S", I want the
list to position on the second entry.


Jan Stempel
Stempel Consulting
Nov 12 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.