Full Version: Scroll through list box
UtterAccess Forums > Microsoft® Access > Access Forms
I have a list box on a form. This list box can be populated with a variable amount of records. What I want to do is have users press a button and the program will scroll through the list box line by line. On each line it will then save the records it finds to a table. When it hits the end of the list I need it to return to the beginning and carry on.
Any ideas how this can be done?
Larry Larsen
Have to say this is an "odd" request.. and don't really understand what the actions/process is doing..!!
Way be you could enlighten us..
OK here is what I am trying to achieve.
I'm trying to set up rota patterns for employees for a couple of years at a time.
Firstly the administrator will enter a start date then an end date which will automatically calculate the number of weeks of rotas requiring generation (in this case 104 weeks, which is 2 years).
Next, at the top of the screen is a start and finish time from Sunday to Saturday. The user will enter the start and end time each day (blank if a day off) and then press a tick icon. This will move the rota into line 1 of the list box. If this employee only does 09:00 to 17:00 all the time then this will be the only rota that requires creating. The 'generate rotas' button when hit will create 1 record per week for 104 weeks.
Some employees have very complicated shifts. For example they can have 1 week Sun to Thur 06:00 to 14:00, then Mon to Fri 14:00 to 22:00 then Mon to Fri 06:00 to 14:00 then Sun to Thur 14:00 to 22:00. In this case I would have 4 rows of data in the list box. So when the 'generate rotas' button is pressed the program should go to row 1 and save week 1's then row 2 then row 3 then row 4 then back to row 1 and row 2 etc until 104 records have been saved.
I think I will have to do a loop inside a loop. The bit I am struggling with is how to loop through the list box and when it hits the bottom of the list go back to the top and start again.
Any help would be greatfully accepted.
It does sound complex ... and honestly did not have time to digest it all, but to loop through a list box from a selected, back to that selected spot, I would use the .ListIndex property ... Something like ...
Do Until lngRecordsCreated = lngRecordsNeeded
    '<code to create your record>
    ' increment your record counter
    lngRecordsCreated = lngRecordsCreated + 1
    'Move to the next row in the list box.  Note, you can only set the ListIndex if the list box has
    'the focus.
    If Me.ListBoxName.ListIndex = Me.ListBoxName.ListCount - 1 Then
        Me.ListBoxName.ListIndex = 0
        Me.ListBoxName.ListIndex = Me.ListBoxName.ListIndex + 1
    End If

{Note ... AIR CODE!!!! }
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.