gwh
04-12-2008, 08:37 AM
Hi everyone,
I've put together a multipage userform and on one of the pages I have two textboxes and one list box. The user enters milestone information into one of the textboxes and a date into the second box. Once data is entered into both of the textboxes, I have an "add" button to insert the information into a 2 column listbox. The user continues to add as many date/milestone pairs as needed.
I also have a delete button to delete the entries from the listbox and another button to edit an entry that was put in the listbox.
The problem at the moment is with the edit process. It works okay, ie. when pressed the row in the list box that's clicked on is transferred from the listbox back into the two textboxes so the entries can be edited, then the user can click "add" again to reinsert the information back into the listbox. The only thing is that when they re-add the info after editing, it doesn't appear in the right order, ie. it appears at the end of the list in the listbox. Since they need to exist in the listbox in date order, is there a way to either have the entry jump back to the original location it occupied before it was edited or else have "up" and "down" buttons that will move the entry into its correct place?
Below is the code as it is now.
I'd really be grateful if someone could help me out here.
Private Sub cmdAddTiming_Click()
With lstTiming_Milestones
.AddItem txtTiming_Milestone.Value
.Column(1, .ListCount - 1) = txtTiming_Date.Value
End With
txtTiming_Milestone.Value = ""
txtTiming_Date.Value = ""
End Sub
Private Sub cmdDeleteTiming_Click()
With lstTiming_Milestones
.RemoveItem (.ListIndex)
End With
End Sub
Private Sub cmdEditTiming_Click()
With lstTiming_Milestones
txtTiming_Milestone.Value = .Column(0, .ListIndex)
txtTiming_Date.Value = .Column(1, .ListIndex)
.RemoveItem (.ListIndex)
End With
End Sub
Dim i As Long
Dim mtable As Table
Dim mrow As Row
Set mtable = _
ActiveDocument.Bookmarks("Timing_Milestones").Range.Tables(1)
With lstTiming_Milestones
For i = 1 To .ListCount
Set mrow = mtable.Rows.Add
mrow.Range.Font.Bold = False
mrow.Range.Font.Italic = False
mrow.Range.Font.Color = RGB(0, 0, 0)
mrow.Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphLeft
mrow.Cells(1).Range.Text = .Column(0, i - 1)
mrow.Cells(2).Range.Text = .Column(1, i - 1)
Next i
End With
I've put together a multipage userform and on one of the pages I have two textboxes and one list box. The user enters milestone information into one of the textboxes and a date into the second box. Once data is entered into both of the textboxes, I have an "add" button to insert the information into a 2 column listbox. The user continues to add as many date/milestone pairs as needed.
I also have a delete button to delete the entries from the listbox and another button to edit an entry that was put in the listbox.
The problem at the moment is with the edit process. It works okay, ie. when pressed the row in the list box that's clicked on is transferred from the listbox back into the two textboxes so the entries can be edited, then the user can click "add" again to reinsert the information back into the listbox. The only thing is that when they re-add the info after editing, it doesn't appear in the right order, ie. it appears at the end of the list in the listbox. Since they need to exist in the listbox in date order, is there a way to either have the entry jump back to the original location it occupied before it was edited or else have "up" and "down" buttons that will move the entry into its correct place?
Below is the code as it is now.
I'd really be grateful if someone could help me out here.
Private Sub cmdAddTiming_Click()
With lstTiming_Milestones
.AddItem txtTiming_Milestone.Value
.Column(1, .ListCount - 1) = txtTiming_Date.Value
End With
txtTiming_Milestone.Value = ""
txtTiming_Date.Value = ""
End Sub
Private Sub cmdDeleteTiming_Click()
With lstTiming_Milestones
.RemoveItem (.ListIndex)
End With
End Sub
Private Sub cmdEditTiming_Click()
With lstTiming_Milestones
txtTiming_Milestone.Value = .Column(0, .ListIndex)
txtTiming_Date.Value = .Column(1, .ListIndex)
.RemoveItem (.ListIndex)
End With
End Sub
Dim i As Long
Dim mtable As Table
Dim mrow As Row
Set mtable = _
ActiveDocument.Bookmarks("Timing_Milestones").Range.Tables(1)
With lstTiming_Milestones
For i = 1 To .ListCount
Set mrow = mtable.Rows.Add
mrow.Range.Font.Bold = False
mrow.Range.Font.Italic = False
mrow.Range.Font.Color = RGB(0, 0, 0)
mrow.Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphLeft
mrow.Cells(1).Range.Text = .Column(0, i - 1)
mrow.Cells(2).Range.Text = .Column(1, i - 1)
Next i
End With