I'm trying to put into practice things I've learnt here y'know.
And at least part of this is fab (and making me very happy!).
So, I have a project which will have several forms. I on;y want top wrote the code to populate the list boxes once, as they will be the same in each case. So, I have this code in my module
and in my form code I do this:
So far so good!
But, I wanted to 'read' these list boxes in the module too... so I have this in the module
Called like this from the form
Logically, this ought to work. But, as I have preselected an item in each list (.listindex = 6) for each box, unless I physically click on that item (even though it appears highlighted and selected the code doesn't seem to find it. It find at item which is true - but doesn't return the value to the dimmed string if I watch the code.
But it only does this for the second list box so its populating ItemBand but not RxBand.
(I tried to put them both insid a frame to look nice - then it only found the first one instead!)
I'm clearly missing something here - any ideas?
Fee
"The cure for anything is salt water – sweat, tears, or the sea." Isak Dinesen
And at least part of this is fab (and making me very happy!).
So, I have a project which will have several forms. I on;y want top wrote the code to populate the list boxes once, as they will be the same in each case. So, I have this code in my module
Code:
Sub PopulateLists(Form)
'populate the items list and price lists on each form
'call from the form code with form name in brackets
With Form
With .lstItems
.AddItem "0 - 430"
.AddItem "431 - 538"
.AddItem "539 - 646"
.AddItem "647 - 753"
.AddItem "754 - 861"
.AddItem "862 - 968"
.AddItem "969 - 1344"
.AddItem "1345 - 1882"
.AddItem "1883 - 2151"
.AddItem "2152 - 2689"
.AddItem "2690 - 3226"
.AddItem "3227 - 3764"
.AddItem "3765 - 4302"
.AddItem "4303 - ...."
.ListIndex = 6
End With
With .lstPrices
.AddItem "0 - 2000"
.AddItem "2001 - 4000"
.AddItem "4001 - 6000"
.AddItem "6001 - 8000"
.AddItem "8001 - 10000"
.AddItem "10001 - 12000"
.AddItem "12001 - 14000"
.AddItem "14001 - 16000"
.AddItem "16001 - 18000"
.AddItem "18001 - 20000"
.AddItem "20001 - 22000"
.AddItem "22001 - 24000"
.AddItem "24001 - ...."
.ListIndex = 6
End With
End With
End Sub
Code:
Private Sub userform_activate()
Call PopulateLists(SingleOptions)
End Sub
But, I wanted to 'read' these list boxes in the module too... so I have this in the module
Code:
Sub ReadLists(Form)
'read the selected items from both listboxes on each form
'call from the form code with the form name in brackets
Dim ItemBand As String
Dim RxBand As String
Dim I As Integer
Dim P As Integer
For I = 0 To Form.lstItems.ListCount - 1
If Form.lstItems.Selected(I) = "True" Then ItemBand = Form.lstItems.Value
Next I
For P = 0 To Form.lstPrices.ListCount - 1
If Form.lstPrices.Selected(P) = "True" Then RxBand = Form.lstPrices.Value
Next P
MsgBox ItemBand & vbCrLf & RxBand
End Sub
Code:
Private Sub cmdSingOK_click()
Call ReadLists(SingleOptions)
Unload Me
End Sub
Logically, this ought to work. But, as I have preselected an item in each list (.listindex = 6) for each box, unless I physically click on that item (even though it appears highlighted and selected the code doesn't seem to find it. It find at item which is true - but doesn't return the value to the dimmed string if I watch the code.
But it only does this for the second list box so its populating ItemBand but not RxBand.
(I tried to put them both insid a frame to look nice - then it only found the first one instead!)
I'm clearly missing something here - any ideas?
Fee
"The cure for anything is salt water – sweat, tears, or the sea." Isak Dinesen