Link to home
Start Free TrialLog in
Avatar of leachj
leachj

asked on

How to reposition an item in a listbox to the top of the list?

I have a combo box that is populated with a list of items.  When the user selects one of the items from the dropdown, it is inserted into a a table.  A listbox displays all records in the table and is based on a query.  After the combo selection, the listbox is requeried and sorted on the records that have been entered.  I would like to display the most recent selection of the combo box at the top of the listbox list and leave the rest sorted.  How do I move the most recently added item to the top of the listbox list?  There may only be 4-6 items in the listbox but could be more.  Probably not enough to scroll.  I would like to see the item selected in the combo box at the top of the listbox list with the other items displayed beneath it without disturbing there sort order.

Thanks,
John
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

what is the rowsource of the listbox?
Avatar of leachj
leachj

ASKER

The row source is an sql select statement.  Selecting all records from the diagnosis table that match the patient id.
post the sql statement, and to which field does the selected item from the combo box goes?
Generally, you will have to provide a sorting mechanism if you want to do these sorts.

If the table that is used for the listbox contains an autonumber field, then you could use that as the sort mechanism, something like:

SELECT Field1 FROM yourTable ORDER BY ID DESC

Since Autonumber fields are always increasing, the order of fields added to that table will be inverted by using the DESC operator in the ORDER BY clause.
Avatar of leachj

ASKER

SELECT tblDemographics.IDNO, tblPatientDiagnosisICD9.Diagnosis, tblPatientDiagnosisICD9.ICD9 FROM tblDemographics LEFT JOIN tblPatientDiagnosisICD9 ON tblDemographics.IDNO=tblPatientDiagnosisICD9.IDNO WHERE (((tblDemographics.IDNO)=[forms]![frmDemographics]![idno])) ORDER BY tblPatientDiagnosisICD9.Diagnosis;

The selected item in combo box is written to IDNO and Diagnosis.  
As you can see, it is already sorted.  The combo box lets the user select a primary diagnosis (there can be multiple diagnoses).  I want to put the primary diagnosis at the top of the otherwise sorted list.
The problem I see with using an integer field in the table, if the primary diagnosis is changed at some point, that field would have to be  changed and the new diagnosis assigned a rank to allow it to float to the top.  Thought I might be able to just let the normal sort happen with a requery and then move the primary diagnosis up the list to the top.
can you post sample data.. we need it to determine how the sorting should be done..

what type of data is the IDNO field?
what type of data is the  Diagnosis field?
Avatar of leachj

ASKER

AID          IDNO                 Diagnosis                                ICD9      
6        36            Intestinal infection due to e coli      008.04      

AID is auto number field
IDNO is the patients ID number used to uniquely identify the record related to other tables
Diagnosis is text.
ASKER CERTIFIED SOLUTION
Avatar of GRayL
GRayL
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial