Record navigation based on listbox

supmktg

Registered User.
Local time
Yesterday, 23:50
Joined
Mar 25, 2002
Messages
360
On a form called "frmRecordList" I have a multiselect listbox "lstRecords" and a command button that opens a form "frmViewDetail" based on the selection in the listbox. I would like to add record navigation buttons to "frmViewDetail" so I can move down (or up) the selected records in the listbox on "frmRecordList".

I know that I can refer to 'Forms!frmRecordList!lstRecords.column(0,row)' , but how do I determine the next (or previous) selected row? I appreciate any help that I can get.

Thanks,
Sup
 
If all you get are the selected records, then you should know where you have started. I'll assume at the first selected item in the list. That means you can go up or down the list by adding or subtracting 1 from where you are now. The bounderies would be 0 and .Selected.Count - 1. That way you would know that you are not trying to get a list item that was not selected.
 
I've attached a sample of what I'm trying to do.

On DblClick of a listbox row frmViewDetail opens and shows the record in that row. There are next & previous buttons that will navigate up and down the listbox using the ListIndex property adding or subtracting 1 from the current index. This works OK from the DblClick of a single row.

If multiple selections are made, the 'View Detail' button opens frmViewDetail showing the first record selected. Since there are multiple selections, the ListIndex property won't work to navigate from the current record. How can I determine which records are selected, and then navigate to them.

Thanks,
Sup
 

Attachments

Sorry I did not know the correct names of the properties and collection for the rows selected in a list or combo box. The collection for the rows selected is .ItemsSelected. Count is one of those properties. So you can go from ListBoxName.ItemsSelected(x) where x is from 0 to ListBoxName.ItemsSelected.Count - 1. This will work just like you described, except it will only give you the items selected rather than the whole list as it appears you can already do.
 
I got the count part, this works:

Code:
Dim cntSelected as integer
cntSelected = [Forms]![frmRecordList]![lstRecords].ItemsSelected.Count

But how can I determine which listbox row I'm on, and which one is the next (or previous) selected row?

Thanks,
Sup
 
I just tried to explain it, but then I looked up ItemsSelected in Access help. I believe that will explain it to you quite well. There are two examples with the help text that I think you can find very useful too. If you have any more questions after working with the help examples, please ask away.
 
After reviewing ItemsSelected in help, I can count selected items and loop through selected items. What I can't figure out how to do is determine which of the selected items I am currently viewing, and how to navigate to the next (or previous) selected item.

Any further direction would be greatly appreciated.

Thanks,
Sup
 
If you start at the first selected item, it's index number will be 0 (zero). Therefore, the next one will be 1, then 2, etc. Going backwards from where ever you are would be 3, then 2, etc. By keeping track of where you are within the list by using a Static variable in your navigation routine, you should always know if you can go forward, backward, or not.
I am assuming that you are using the list of items in the list box as an "index" to the records you want to show the user. In the form where the user can see these records, when they press the "Next" record button, you should be able to set a hidden variable in the form that holds the list box so when you close the "viewing" form, your main form will know if the user wants to go forward, backward, or quit. Another idea would be to have a function on your main form that can be called from the "viewing" form. This function would pass to the "viewing" form the record detail from the list box of the next record to display. Parameters passed to this function in the main form would be which direction to go, forward or backward. Of course the function in the main form would have to use the Static variable that would "remember" which index number of the selected items in the list box is the current item. Then just add or subtract from that number depending on the direction the user wants to go.
 
By the way, can you navigate through the entire list now, with showing the user the detail form for each item in the list box?
 
Yes, download the attachment in my second post. You can scroll through the list, if you open the detail form via a DblClick. But I don't want the entire list, I want only the selected items.

Vic, I understand the theory behind your explanations, but (though I've tried) I'm not able to translate the theory into code that will grab the index of the record currently being viewed, and then find the next or previous selected item.

Can someone point me in the right direction with sample code. "Air code" will do if it just gets me started in the right direction.

Thanks,
Sup
 
Sorry about that, I really felt it would not be too difficult. I DO stand corrected. I'm sorry I don't have the time to help more, as this is something I think is a great idea, and now I really want to help you conquer it! But I have a ton of stuff to do today, and I've already spent an hour on it, which I really don't have. If you don't get this solved within the next week, I'll be back to help. I have attached your database with my changes (read attempts) at getting this thing to work. Something that worked for you, and is NOT working for me, and I sure don't know why is adding one to the existing ListIndex. Access is telling me I'm using ListIndex wrong.

The last thing I was trying was to use your code of showing all the list items, but only showing the ones selected by selecting the next item (+/-) then testing the .Selected property.

Good luck, and please post the solution if you find it.

Again, sorry I don't have more time.
 
I've been unable to find a way to navigate the selected items, though I know there must be a way to do it.

Any new direction would be greatly appreciated!

Thanks,
Sup
 

Users who are viewing this thread

Back
Top Bottom