Advertisement

04.20.2008 at 03:17AM PDT, ID: 23337558
[x]
Attachment Details

Manipulating values in listbox in Word VBA userform

Asked by gwh2 in VB Controls, Visual Basic Programming, Microsoft Word

Tags: Microsoft, Word, 2003, 2004, 2007, VBA

Hi everyone,

I need some help with revising some code relating to a listbox on a page on a multi-page vba userform in Word. On the page 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 milestone /date pairs as needed.

I also have a delete button to delete the entries from the listbox if needed.

I'm trying to implement some functionality so that after the entries have been entered into the listbox, I'd like the user to be able to click on any row and have the values in the two columns jump back into the two text boxes, ie. milestone and date, so that they can edit these values if required. Once the values are edited, I have a "change" button which would do the following:

I have a Public array in a standard module, separate from the userform module, with the following code:

Option Explicit
Public MyList() As String

The following is the code relating to the change button:

Private Sub cmdChange_Click()
    Dim var
    On Error Resume Next
    For var = 0 To lstTiming_Milestones.ListCount
        ReDim Preserve MyList(var)
        MyList(var) = lstTiming_Milestones.List(var)
    Next
    MyList(mySelected) = txtTiming_Milestone.Text
    MyList(mySelected) = txtTiming_Date.Text
    lstTiming_Milestones.Clear
    lstTiming_Milestones.List = MyList()
End Sub

I Redim the array with the items of the listbox and get the ListIndex of the selected item. I then make the array value the new value (the edited value in the textbox), I clear the Listbox, and then repopulate it with the new array.

When I test, I enter text into the two boxes called txtTiming_Milestone and txtTiming_Date. When I press "add" the data gets inserted into the two columns of the listbox. When I click on the row in the listbox, the values get inserted back into the two textboxes as they should and I can edit them, but when I click change the edited date gets inserted in the first column of the listbox (which is where the milestone should go) and the milestone disappears altogether. I'm wondering if the code in the following code block is incorrect?

Private Sub lstTiming_Milestones_Change()
    txtTiming_Milestone.Text = lstTiming_Milestones.Text
    txtTiming_Date.Text = lstTiming_Milestones.Text
    mySelected = lstTiming_Milestones.ListIndex
End Sub

I have all the other relevant code below and wondered if someone could take a look to tell me what I might be doing wrong?

I'd really be grateful if someone could help me out here.
Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
Option Explicit 
Dim bAllowValidate As Boolean 
Public mySelected As Long 
 
Private Sub UserForm_Initialize() 
     
    MultiPage1.Value = 0 
     
End Sub 
 
 
Private Sub cmdChange_Click() 
    Dim var 
    On Error Resume Next 
    For var = 0 To lstTiming_Milestones.ListCount 
        ReDim Preserve MyList(var) 
        MyList(var) = lstTiming_Milestones.List(var) 
    Next 
    MyList(mySelected) = txtTiming_Milestone.Text 
    MyList(mySelected) = txtTiming_Date.Text 'extra line to accommodate 2nd text box
    lstTiming_Milestones.Clear 
    lstTiming_Milestones.List = MyList() 
End Sub 
 
 
Private Sub lstTiming_Milestones_Change() 
    txtTiming_Milestone.Text = lstTiming_Milestones.Text 
    txtTiming_Date.Text = lstTiming_Milestones.Text 'extra line to accommodate 2nd text box
    mySelected = lstTiming_Milestones.ListIndex 
End Sub 
 
 
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
[+][-]04.20.2008 at 04:07AM PDT, ID: 21395667

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.20.2008 at 04:33AM PDT, ID: 21395726

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.20.2008 at 04:43AM PDT, ID: 21395743

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.20.2008 at 04:44AM PDT, ID: 21395746

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.20.2008 at 04:47AM PDT, ID: 21395752

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.20.2008 at 05:01AM PDT, ID: 21395780

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.20.2008 at 05:02AM PDT, ID: 21395782

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.20.2008 at 06:42AM PDT, ID: 21395983

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.20.2008 at 07:24AM PDT, ID: 21396089

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.20.2008 at 07:31AM PDT, ID: 21396122

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.20.2008 at 08:55AM PDT, ID: 21396494

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.20.2008 at 10:21AM PDT, ID: 21396821

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.20.2008 at 10:30AM PDT, ID: 21396869

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.20.2008 at 10:36AM PDT, ID: 21396904

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.20.2008 at 10:52AM PDT, ID: 21396959

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.20.2008 at 11:10AM PDT, ID: 21397035

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.20.2008 at 11:28AM PDT, ID: 21397108

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.20.2008 at 11:36AM PDT, ID: 21397137

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.20.2008 at 05:14PM PDT, ID: 21398054

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.20.2008 at 05:22PM PDT, ID: 21398077

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.21.2008 at 01:45AM PDT, ID: 21399616

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.21.2008 at 04:17AM PDT, ID: 21400419

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.21.2008 at 05:32AM PDT, ID: 21400904

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.21.2008 at 05:54AM PDT, ID: 21401103

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.21.2008 at 06:21AM PDT, ID: 21401357

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.21.2008 at 06:27AM PDT, ID: 21401415

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.21.2008 at 06:51AM PDT, ID: 21401704

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.21.2008 at 07:13AM PDT, ID: 21401957

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.21.2008 at 07:18AM PDT, ID: 21402007

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: VB Controls, Visual Basic Programming, Microsoft Word
Tags: Microsoft, Word, 2003, 2004, 2007, VBA
Sign Up Now!
Solution Provided By: GrahamSkan
Participating Experts: 1
Solution Grade: A
 
 
[+][-]04.21.2008 at 07:47AM PDT, ID: 21402371

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.21.2008 at 11:07AM PDT, ID: 21404439

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.21.2008 at 11:58AM PDT, ID: 21404851

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.22.2008 at 02:03AM PDT, ID: 21409151

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.22.2008 at 02:32AM PDT, ID: 21409274

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628