By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,959 Members | 1,243 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,959 IT Pros & Developers. It's quick & easy.

Set multiselect property in VB

100+
P: 365
Hello AGAIN

'Nother problem to solve....

im trying to set the MultiSelect property within VB for a list box, and i am using the code

Me.StaffHols.Multiselect = True

and it wont work, it says that i cannot assign a value to the object, ive tried many ways to get this to work (and i have had this working before)

so what am i doing wrong?
Jan 28 '08 #1
Share this Question
Share on Google+
43 Replies


jaxjagfan
Expert 100+
P: 254
Hello AGAIN

'Nother problem to solve....

im trying to set the MultiSelect property within VB for a list box, and i am using the code

Me.StaffHols.Multiselect = True

and it wont work, it says that i cannot assign a value to the object, ive tried many ways to get this to work (and i have had this working before)

so what am i doing wrong?
MultiSelect property is 0, 1 or 2
No Multi, Simple, or Extended
Jan 28 '08 #2

100+
P: 365
yeah i tried that as well same error
Jan 28 '08 #3

NeoPa
Expert Mod 15k+
P: 31,709
I looked in the Help section and two things pop-out :
  1. It is only valid for ListBoxes. make sure it is such and not a ComboBox you're dealing with.
  2. It says it can only be changed when the form is in Design View. This seems strange for code, but may be worth delving into further.
Hope this helps.

PS. Valid values are only {0; 1; 2}. True is not valid. False, being equivalent to 0, is.
Jan 28 '08 #4

ADezii
Expert 5K+
P: 8,679
yeah i tried that as well same error
NeoPa has already pointed you in the right direction, but the Method to change the MultiSelect Property of a List Box while in an Active Form, is not that intuitive. Here is how it is done, let's say you are currently in frmMain and you wish to change the MultiSelect Property of lstMultiSelect:
Expand|Select|Wrap|Line Numbers
  1. Const conNONE As Integer = 0
  2. Const conSIMPLE As Integer = 1
  3. Const conEXTENDED As Integer = 2
  4.  
  5. Application.Echo False
  6.   DoCmd.OpenForm "frmMain", acDesign
  7.     Forms!frmMain![lstMultiselect].MultiSelect = conNONE
  8.                          'OR
  9.     Forms!frmMain![lstMultiselect].MultiSelect = conSIMPLE
  10.                          'OR
  11.     Forms!frmMain![lstMultiselect].MultiSelect = conEXTENDED
  12.                          'OR
  13.   DoCmd.OpenForm "frmMain", acNormal, , , acFormEdit
  14. Application.Echo True
Jan 29 '08 #5

100+
P: 365
Thanks for that, didnt realise i had to set the property in design view, you can do it from the properties menus whilst the form is active, bit odd isnt it.
had to do quite a lot of recoding to compensate for the form "closing and opening"

thanks again

Dan
Jan 29 '08 #6

NeoPa
Expert Mod 15k+
P: 31,709
100 posts Dan - Nice :)
Just as a last point though, it may be worth checking to see if changes made in that state are saved to the form object. If so, you may have to ensure your code handles the situation.
Jan 29 '08 #7

100+
P: 365
Yeah thats one of the things i had to change, for some reason i think its good to "reuse" forms so i have lots or overly complicated code selections so after it has set the multiselect property it sets a value to 1 and then when the form closes (had to use a custom close button) it turns off again.


Got another question now..... same lines... i am using my multiselect in extended mode, so that someone can select a range (most importantly dates) and i want to assign the 1st and last selected (dates) in the list a to a VB variable

i have one idea which is to loop through the items selected and then state

if new value is > old lowest value (date) then set new low value / and similarly with the higher values. is there an easier way!?

Cheers again

ps. 101 now tehe
Jan 29 '08 #8

NeoPa
Expert Mod 15k+
P: 31,709
Yeah thats one of the things i had to change, for some reason i think its good to "reuse" forms so i have lots or overly complicated code selections so after it has set the multiselect property it sets a value to 1 and then when the form closes (had to use a custom close button) it turns off again.


Got another question now..... same lines... i am using my multiselect in extended mode, so that someone can select a range (most importantly dates) and i want to assign the 1st and last selected (dates) in the list a to a VB variable

i have one idea which is to loop through the items selected and then state

if new value is > old lowest value (date) then set new low value / and similarly with the higher values. is there an easier way!?

Cheers again

ps. 101 now tehe
That's about how I'd do it too :) There is a collection of just the selected items of course.
(I'd only replace the "old lowest value" with lower ones though ;)).
Jan 29 '08 #9

100+
P: 365
OK this is how i did that then, seems to work!!

Expand|Select|Wrap|Line Numbers
  1. Dim sdt1 As Date, edt1 As Date, Loop1 As Integer
  2.     For Each row In Me.StaffHols.ItemsSelected
  3.         If Loop1 = 0 Then
  4.             sdt1 = Me.StaffHols.ItemData(row)
  5.             edt1 = Me.StaffHols.ItemData(row)
  6.         End If
  7.             If Me.StaffHols.ItemData(row) < sdt1 Then sdt1 = Me.StaffHols.ItemData(row)
  8.             If Me.StaffHols.ItemData(row) > edt1 Then edt1 = Me.StaffHols.ItemData(row)
  9.         Loop1 = 1
  10.     Next
  11.     'MsgBox "" & sdt1 & " " & edt1
  12.  
Now just have to spend HOURS duin something with that info HOURS i tell you (wont go into detail too boring)

Thanks again for you help

Dan
Jan 29 '08 #10

NeoPa
Expert Mod 15k+
P: 31,709
Look at the following code and notice how the same effect is produced a little more naturally :
Expand|Select|Wrap|Line Numbers
  1. 'Some procedure
  2.   Dim sdt1 As Date, edt1 As Date
  3.  
  4.   sdt1 = #31 Dec 9999#
  5.   edt1 = #1 Jan 1900#
  6.   With Me.StaffHols
  7.     For Each Row In .ItemsSelected
  8.       If .ItemData(Row) < sdt1 Then sdt1 = .ItemData(row)
  9.       If .ItemData(Row) > edt1 Then edt1 = .ItemData(row)
  10.     Next
  11.   End With
  12.   'MsgBox Format(sdt1, "mmm d, yyyy") & " " & Format(edt1, "mmm d, yyyy")
This is a good example of where Variant data types might be used too.
Expand|Select|Wrap|Line Numbers
  1. 'Some procedure
  2.   Dim sdt1 As Variant, edt1 As Variant
  3.  
  4.   'sdt1 & edt1 already set as Null
  5.   With Me.StaffHols
  6.     For Each Row In .ItemsSelected
  7.       If IsNull(sdt1) Or .ItemData(Row) < sdt1 Then sdt1 = .ItemData(row)
  8.       If IsNull(edt1) Or .ItemData(Row) > edt1 Then edt1 = .ItemData(row)
  9.     Next
  10.   End With
  11.   'MsgBox Format(sdt1, "mmm d, yyyy") & " " & Format(edt1, "mmm d, yyyy")
Jan 29 '08 #11

100+
P: 365
That looks good too, any disadvantage to using Variant types?

i think i will use one of your examples, they look tidier, i never thought of using the with.

Dan
Jan 29 '08 #12

ADezii
Expert 5K+
P: 8,679
100 posts Dan - Nice :)
Just as a last point though, it may be worth checking to see if changes made in that state are saved to the form object. If so, you may have to ensure your code handles the situation.
Hello NeoPa, just figured you may want to know that the changes will persist to the List Box when modified in that manner. Just another useless bit of information.
Jan 30 '08 #13

100+
P: 365
Ok new question, i want users to only select consecutive rows (from the Multi Listbox) any ideas ho i can do that?

im thinking an error msg that says please select consecutive records OR ELSE!!!! lol

i have this code:
Expand|Select|Wrap|Line Numbers
  1. For intCurrentRow = 0 To .ListCount - 1
  2.             If .Selected(intCurrentRow) = True Then
  3.             End If
  4.         Next intCurrentRow
  5.  
i also need to check if the item selected is the first and/or last in the list
how could i code that... easily?
Jan 30 '08 #14

ADezii
Expert 5K+
P: 8,679
Ok new question, i want users to only select consecutive rows (from the Multi Listbox) any ideas ho i can do that?

im thinking an error msg that says please select consecutive records OR ELSE!!!! lol

i have this code:
Expand|Select|Wrap|Line Numbers
  1. For intCurrentRow = 0 To .ListCount - 1
  2.             If .Selected(intCurrentRow) = True Then
  3.             End If
  4.         Next intCurrentRow
  5.  
i also need to check if the item selected is the first and/or last in the list
how could i code that... easily?
Here's part of the solution to see if the 1st and/or Last Items in the List Box are selected (lstTest):
Expand|Select|Wrap|Line Numbers
  1. 'Is the 1st Item selected?
  2. If Me![lstTest].Selected(0) Then
  3.   MsgBox "1st Item in the List Selected"
  4. End If
  5.  
  6. 'Is the Last Item Selected
  7. If Me![lstTest].Selected(Me![lstTest].ListCount - 1) Then
  8.   MsgBox "Last Item in List selected"
  9. End If
Jan 30 '08 #15

NeoPa
Expert Mod 15k+
P: 31,709
Hello NeoPa, just figured you may want to know that the changes will persist to the List Box when modified in that manner. Just another useless bit of information.
I'm a bit confused ADezii.
I don't think there are any changes made to anything in the ListBox. All that happens is that two variables are set :S
Jan 31 '08 #16

NeoPa
Expert Mod 15k+
P: 31,709
Ok new question, i want users to only select consecutive rows (from the Multi Listbox) any ideas ho i can do that?
...
Isn't that simply done by setting the .MultiSelect property to Simple? :S (See ADezii's post #5)
Jan 31 '08 #17

ADezii
Expert 5K+
P: 8,679
I'm a bit confused ADezii.
I don't think there are any changes made to anything in the ListBox. All that happens is that two variables are set :S
Sorry NeoPa, you should know by now to ignore me about 80% of the time. By 'persist' I meant the changing of the MultiSelect Property, not actual List Box values.
Jan 31 '08 #18

NeoPa
Expert Mod 15k+
P: 31,709
Ah.
A response to post #7 (which you even quoted - my bad). In that case - Yes, I am interested and thank you :)
Jan 31 '08 #19

ADezii
Expert 5K+
P: 8,679
Ah.
A response to post #7 (which you even quoted - my bad). In that case - Yes, I am interested and thank you :)
Always a pleasure to hear from you!!
Jan 31 '08 #20

100+
P: 365
Isn't that simply done by setting the .MultiSelect property to Simple? :S (See ADezii's post #5)
no on a simple listbox you can just select them one by one, extended you have to use shift/ control or mouse drag to select more than one,

i want to restrict the slections to only allow consecutive rows, because this will reduce my coding needs, so i want a msgbox alerting the user that they must select consecutive rows(dates)

thanks for the help so far tho
Jan 31 '08 #21

NeoPa
Expert Mod 15k+
P: 31,709
In that case I expect you just need to process through the list and detect if all the selections are contiguous. If not, throw up an error message. The coding wouldn't be much different from what I posted in post #11. The basics are there at least. I expect you can take it from there but let us know if you'd like some more help with it.
Jan 31 '08 #22

100+
P: 365
Yeah thats what i expected, but i have a problem thinking about the code

for example if i had a list of 10 and the user selects the last 5 how can i ignore the false (not selected) until after the first true? and then again if they select 3 in the middle i would have to ignore, then "search for continuous" and then not again.

i dont know whether taht makes sense, but i have thought about it for hours and i cant think of a way to do it... usually i use "flags" for things like this but there seems to be to many things to comprehend, the easiest way would be to disable the control button at that form event, but i dont think that is possible, i spose as a cop out i can put a stern instruction to only select consecutive values but if that where to be ignored then it would C@#& up my (following) code

Cheers once more!!
Dan
Jan 31 '08 #23

NeoPa
Expert Mod 15k+
P: 31,709
..., i spose as a cop out i can put a stern instruction to only select consecutive values but if that where to be ignored then it would C@#& up my (following) code
...
Never a good plan :(

Try something like this (You'll have to tidy up the loose edges) :
Expand|Select|Wrap|Line Numbers
  1. 'Some procedure
  2.   Dim sdt1 As Variant, edt1 As Variant, LastRow As Variant
  3.  
  4.   'sdt1, edt1 & LastRow already set as Null
  5.   With Me.StaffHols
  6.     For Each Row In .ItemsSelected
  7.       If IsNull(LastRow) Then LastRow = Row - 1
  8.       If Row = (LastRow + 1) Then
  9.         LastRow = Row
  10.       Else
  11.         'Processing to highlight problem - possibly
  12.         'Call MsgBox("Selected lines must all be contiguous.")
  13.         Exit Sub
  14.       End If
  15.       If IsNull(sdt1) Or .ItemData(Row) < sdt1 Then sdt1 = .ItemData(row)
  16.       If IsNull(edt1) Or .ItemData(Row) > edt1 Then edt1 = .ItemData(row)
  17.     Next
  18.   End With
  19.   'Call MsgBox(Format(sdt1, "mmm d, yyyy") & " " & Format(edt1, "mmm d, yyyy"))
Feb 1 '08 #24

ADezii
Expert 5K+
P: 8,679
Yeah thats what i expected, but i have a problem thinking about the code

for example if i had a list of 10 and the user selects the last 5 how can i ignore the false (not selected) until after the first true? and then again if they select 3 in the middle i would have to ignore, then "search for continuous" and then not again.

i dont know whether taht makes sense, but i have thought about it for hours and i cant think of a way to do it... usually i use "flags" for things like this but there seems to be to many things to comprehend, the easiest way would be to disable the control button at that form event, but i dont think that is possible, i spose as a cop out i can put a stern instruction to only select consecutive values but if that where to be ignored then it would C@#& up my (following) code

Cheers once more!!
Dan
I threw together this ugly block of code for you, and it may/may not help you in this matter. This code will Print to the Immediate Window all Contiguous, (single and multiple), Selections made within a Multi Column List Box named lstTest. I opted for the older syntax (Selected vs ItemsSelected) because I thought it would be easier to follow. It has been tested and actually works quite well, after all looks aren't everything (LOL). Let me know if you need any explanations for the code.
Expand|Select|Wrap|Line Numbers
  1. Dim intItemsSelected As String, intCounter As Integer
  2. Dim blnContiguous As Boolean
  3.  
  4. intItemsSelected = Me![lstTest].ItemsSelected.Count
  5.  
  6. 'Must have at least 2 Items Selected to be contiguous
  7. If intItemsSelected < 2 Then Exit Sub
  8.  
  9. For intCounter = 0 To Me![lstTest].ListCount - 1
  10.   If Me![lstTest].Selected(intCounter) Then
  11.     If intCounter = 0 Then      '1st Item in the List
  12.       If Me![lstTest].Selected(intCounter + 1) Then      '1st & 2nd Items Selected
  13.         Debug.Print Me![lstTest].Column(1, 0) & " " & _
  14.                     Me![lstTest].Column(0, 0) & " is Contiguous"
  15.           blnContiguous = True
  16.       Else
  17.         blnContiguous = False
  18.       End If
  19.     ElseIf intCounter = Me![lstTest].ListCount - 1 Then      'Last Item in the List
  20.        If Me![lstTest].Selected(intCounter - 1) Then
  21.          Debug.Print Me![lstTest].Column(1, intCounter) & " " & _
  22.                      Me![lstTest].Column(0, intCounter) & " is Contiguous"
  23.            blnContiguous = True
  24.        Else
  25.          blnContiguous = False
  26.        End If
  27.     Else      '> 2 Items Selected, Selected Item is not the 1st or Last
  28.       If Me![lstTest].Selected(intCounter - 1) Or Me![lstTest].Selected(intCounter + 1) Then
  29.         Debug.Print Me![lstTest].Column(1, intCounter) & " " & _
  30.                     Me![lstTest].Column(0, intCounter) & " is Contiguous"
  31.           blnContiguous = True
  32.       Else
  33.         blnContiguous = False
  34.       End If
  35.     End If
  36.   End If
  37. Next
Feb 1 '08 #25

100+
P: 365
That seems to work, however not all the time, i was testing it and if the list had 5 rows it is possible to select the top two and the last two i expanded (number of rows) that and it is still aparent, any ideas?

hope that makes sense

Thanks
Dan
Feb 1 '08 #26

ADezii
Expert 5K+
P: 8,679
That seems to work, however not all the time, i was testing it and if the list had 5 rows it is possible to select the top two and the last two i expanded (number of rows) that and it is still aparent, any ideas?

hope that makes sense

Thanks
Dan
Sorry Dan, not exactly sure what you mean. Please clarify.
Feb 1 '08 #27

NeoPa
Expert Mod 15k+
P: 31,709
That seems to work, ...
Referring to which post?
Feb 1 '08 #28

100+
P: 365
Sorry Dan, not exactly sure what you mean. Please clarify.
it doesnt work 100% basically
it is still possible to miss out the middle row/s

cheers
Feb 2 '08 #29

ADezii
Expert 5K+
P: 8,679
it doesnt work 100% basically
it is still possible to miss out the middle row/s

cheers
Hello Dan2kx, when I tested it, it worked on all 'Contiguous' Selections, which is exactly what it was designed to do. Would it be possible to Attach your Test Database for my own curiosity?
Feb 2 '08 #30

100+
P: 365
Hello again, i added a line of code at the tob so that i could get an msgbox to work, which is where the problem was, but without that line it works incorrectly (the output) could you explain to me the prupose of the debug.print aswell please..

Thanks
Dan

Attachment to follow
Attached Files
File Type: zip Test Row select.zip (16.9 KB, 80 views)
Feb 2 '08 #31

NeoPa
Expert Mod 15k+
P: 31,709
Debug.Print simply displays the values you've added as parameters to the Immediate pane of the VBA window.

Alt-F11 to open the VBA window then Ctrl-G to open the Immediate pane.
That way you can see what's been displayed.
Feb 2 '08 #32

ADezii
Expert 5K+
P: 8,679
Hello again, i added a line of code at the tob so that i could get an msgbox to work, which is where the problem was, but without that line it works incorrectly (the output) could you explain to me the prupose of the debug.print aswell please..

Thanks
Dan

Attachment to follow
I think that we were slightly off track - simply a difference in semantics. I adjusted the code, selected Items 1, 2, 4, 6, 8, 9, and 10, then Attached the modified Database. I also displayed the outcome below. Let me know what you think. I think the problem was your interpretation of what exactly blnContiguous represents, and I also failed to explain it fully, actually you don't even need it.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command2_Click()
  2. Dim intItemsSelected As String, intCounter As Integer
  3. Dim blnContiguous As Boolean
  4. 'Line1:
  5. intItemsSelected = Me![lstTest].ItemsSelected.Count
  6.  
  7. 'Must have at least 2 Items Selected to be contiguous
  8. If intItemsSelected < 2 Then GoTo Line2
  9.  
  10. For intCounter = 0 To Me![lstTest].ListCount - 1
  11.     If Me![lstTest].Selected(intCounter) Then
  12.         If intCounter = 0 Then      '1st Item in the List
  13.             If Me![lstTest].Selected(intCounter + 1) Then      '1st & 2nd Items Selected
  14.                 Debug.Print Me![lstTest].Column(1, 0) & " is Contiguous"
  15.             Else
  16.                 Debug.Print Me![lstTest].Column(1, 0) & " is not Contiguous"
  17.             End If
  18.         Else
  19.             If intCounter = Me![lstTest].ListCount - 1 Then      'Last Item in the List
  20.                 If Me![lstTest].Selected(intCounter - 1) Then
  21.                     Debug.Print Me![lstTest].Column(1, intCounter) & " is Contiguous"
  22.                 Else
  23.                     Debug.Print Me![lstTest].Column(1, intCounter) & " is not Contiguous"
  24.                 End If
  25.             Else      '> 2 Items Selected, Selected Item is not the 1st or Last
  26.                 If Me![lstTest].Selected(intCounter - 1) Or Me![lstTest].Selected(intCounter + 1) Then
  27.                     Debug.Print Me![lstTest].Column(1, intCounter) & " is Contiguous"
  28.                 Else
  29.                     Debug.Print Me![lstTest].Column(1, intCounter) & " is not Contiguous"
  30.                 End If
  31.             End If
  32.         End If
  33.     End If
  34. Next
  35.     GoTo Line2
  36. Line2:
  37. 'lots of code here
  38.     'MsgBox "Success"
  39. End Sub
  40.  
OUTPUT (Selected Items):
Expand|Select|Wrap|Line Numbers
  1. One is Contiguous
  2. Two is Contiguous
  3. Four is not Contiguous
  4. Six is not Contiguous
  5. Eight is Contiguous
  6. Nine is Contiguous
  7. Ten is Contiguous
Feb 2 '08 #33

100+
P: 365
I'm afraid i still cant get it to reproduce, what i want is a msgbox to warn that selected rows have to be consecutive(only if they arent)(which i can do myself) but the code still allows the the top two and the bottom two to be selected and the rest in the middle dont flag, they are ignored, what you have done so far is good though and i thank you for your time, but i do need to make it fool proof, what i intend to do with this is to use the date range selected and then split one record into 3 (excluding the original)

thanks again

Dan
Feb 2 '08 #34

NeoPa
Expert Mod 15k+
P: 31,709
You mean it must be a single contiguous range?
Like a single drag-stroke with the mouse or a Shift-click?
Feb 2 '08 #35

100+
P: 365
You mean it must be a single contiguous range?
Like a single drag-stroke with the mouse or a Shift-click?
Yup thats right, the list (of dates, along with other infor) is indefinate, but the user should only be able to select a "period" from the list it would be nice to destinguish weither the whole list is selected, - cos i want an "error" message, but they can select any other continuous list from the list, and if they dont select a continuous list then another "error" message is displayed

thanks again
Feb 2 '08 #36

ADezii
Expert 5K+
P: 8,679
Yup thats right, the list (of dates, along with other infor) is indefinate, but the user should only be able to select a "period" from the list it would be nice to destinguish weither the whole list is selected, - cos i want an "error" message, but they can select any other continuous list from the list, and if they dont select a continuous list then another "error" message is displayed

thanks again
How about:
  1. De-selecting Selected Items that are not Contiguous?
  2. Checking for Multiple Contiguous Selections, and if found exiting the Routine and notifying the User?
  3. Would this logic work?
Feb 3 '08 #37

ADezii
Expert 5K+
P: 8,679
You mean it must be a single contiguous range?
Like a single drag-stroke with the mouse or a Shift-click?
Hey NeoPa, what in the world would I do if I didn't have you around clarifying things for me? (LOL). Interesting problem, hey?
Feb 3 '08 #38

NeoPa
Expert Mod 15k+
P: 31,709
Yup thats right, the list (of dates, along with other infor) is indefinate, but the user should only be able to select a "period" from the list it would be nice to destinguish weither the whole list is selected, - cos i want an "error" message, but they can select any other continuous list from the list, and if they dont select a continuous list then another "error" message is displayed

thanks again
Dan,

In that case you may want to look back at post #24. ADezii's code and ideas can also work for you in this - but I think that gives you the fairly concise logic for what you need.

By the way - my use of the term contiguous was not a lapse in spelling (or even a typo). Continuous is similar but not what I was saying.
Feb 3 '08 #39

NeoPa
Expert Mod 15k+
P: 31,709
Hey NeoPa, what in the world would I do if I didn't have you around clarifying things for me? (LOL). Interesting problem, hey?
I don't get involved with so many threads nowadays ADezii, but you seem to be, so I can sometimes help. It's always useful to have more than one involved, especially as understanding a problem simply from what's posted is actually quite difficult generally. I certainly find myself getting confused very often. There's rarely a time I don't have at least a couple of threads outstanding where I've simply asked for the question to be clarified.

It's not even always badly expressed questions. Some are just harder to express in words.

Interesting? Yes.
Feb 3 '08 #40

ADezii
Expert 5K+
P: 8,679
I don't get involved with so many threads nowadays ADezii, but you seem to be, so I can sometimes help. It's always useful to have more than one involved, especially as understanding a problem simply from what's posted is actually quite difficult generally. I certainly find myself getting confused very often. There's rarely a time I don't have at least a couple of threads outstanding where I've simply asked for the question to be clarified.

It's not even always badly expressed questions. Some are just harder to express in words.

Interesting? Yes.
Just wanted to let you know that your help is always appreciated. After a while one Thread seems to blend into another. (LOL).
Feb 3 '08 #41

NeoPa
Expert Mod 15k+
P: 31,709
That's good & I'm very pleased to hear it. I really don't know what we'd do without your input on so many threads. Keep going is all I ask :)
Feb 3 '08 #42

ADezii
Expert 5K+
P: 8,679
Yup thats right, the list (of dates, along with other infor) is indefinate, but the user should only be able to select a "period" from the list it would be nice to destinguish weither the whole list is selected, - cos i want an "error" message, but they can select any other continuous list from the list, and if they dont select a continuous list then another "error" message is displayed

thanks again
The code has been re-revised, and now:
  1. Deselects any 'non-contiguous', selected Items. You can easily change this Default behavior by easily displaying a MsgBox, but this may not be practical if many 'non-contiguous' selections are made. This is up to you.
  2. If 1 or no Items are selected, a MsgBox is displayed to the User, and an Exit is made from the code routine.
  3. The major stumbling block is to detect if 'multiple', 'contiguous', selections are made, e.g.(Items 1, 2 and Items 13, 14, and 15 are selected). From your indications, there can only be 1 'contiguous', selection and the detection of this condition is, at the moment, not so easy to resolve.
  4. Keep in touch, I am still trying to resolve this issue for you.
  5. P.S. - See Attachment.
Feb 3 '08 #43

100+
P: 365
I overlooked NeoPa's suggested code in #24
Expand|Select|Wrap|Line Numbers
  1. If IsNull(LastRow) Then LastRow = Row - 1
  2.       If Row = (LastRow + 1) Then
  3.         LastRow = Row
  4.       Else
  5.         'Processing to highlight problem - possibly
  6.         'Call MsgBox("Selected lines must all be contiguous.")
  7.         Exit Sub
  8.       End If
  9.  
and that seems to work
Feb 3 '08 #44

Post your reply

Sign in to post your reply or Sign up for a free account.