custom sort order

  • Thread starter Thread starter mike
  • Start date Start date
M

mike

Hello all,

I have a table called tblProjectTasks that contains
information about tasks that need to be done for each
project. The tasks are listed on a continous form for
each project. The user needs to be able to change and
save the order in which the tasks are displayed for each
project. How could I accomplish this?

I was thinking of having a "change sort order" button that
would launch a form with a listbox that contained the
tasks. The user could then move a selected item up or
down the list as needed. Once they were finished, I would
would loop through the listbox and write each row number
to tblProjectTasks and use that as the sort order. Is
this a good approach? If so, any examples on how to
accomplish this would be greatly appreciated.


Thanks in advance
 
mike said:
Hello all,

I have a table called tblProjectTasks that contains
information about tasks that need to be done for each
project. The tasks are listed on a continous form for
each project. The user needs to be able to change and
save the order in which the tasks are displayed for each
project. How could I accomplish this?

I was thinking of having a "change sort order" button that
would launch a form with a listbox that contained the
tasks. The user could then move a selected item up or
down the list as needed. Once they were finished, I would
would loop through the listbox and write each row number
to tblProjectTasks and use that as the sort order. Is
this a good approach? If so, any examples on how to
accomplish this would be greatly appreciated.


The way I do that kind of thing is to use two command
buttons on the form (no separate form). The buttons would
move the current record up or down by editing the field that
is used to sort the records.

Here's a move down button's click procedure:

Private Sub cmdMoveDown_Click()
Dim lngCur As Long
Dim lngNext As Long

With Me.RecordsetClone
.Bookmark = Me.Bookmark
lngCur = !SortNum
.MoveNext
If .EOF Then
Beep
Exit Sub
End If
lngNext = !SortNum
.Edit
!SortNum = lngCur
.Update
.MovePrevious
.Edit
!SortNum = lngNext
.Update

Me.Requery
.FindFirst "SortNum = " & lngNext
Me.Bookmark = .Bookmark
End With
End Sub

The move up button's code is the same with the next and
previous changed around.

If the task list form is actually a subform and you want the
buttons on the main form, then xhange the With statement:

With subformcontrolname.Form.RecordsetClone
 
Back
Top