Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to program multi-select list box?

Hi all,

I am a begginer in programming Excel forms, and I ran into
an issue I don't know how to resolve. Please help!

I have a multi-selection list box, and I use "on Change"
event to do some things whenever user changes selections.
It works fine, but I have problem initializing the list.

When the form is activated, I want to restore the
selections saved when a user closed the form. So I go item
by item and set their "Selected" status according to the
status array I saved on exit. However, every time it
triggers "Change" event, and everything gets screwed.

Is there a way to turn-off the Change event while
manupulating control values programmatically? Or have the
control to react only on changes casued by the user? Or
maybe I am taking a completely wrong approach?

Thanks!
RADO



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 79
Default How to program multi-select list box?

Edwin,

thanks a lot! It works. I appreciate your time and advice.

Sincerely -
RADO


"Edwin Tam (MS MVP)" wrote in message
...
RADO, I tell you that you raised a VERY interesting topic!
You topic relates to:
1) You got some code which will be executed upon the Change event of a

control.
2) You got some other code which will change the control in (1).
3) You don't want the code in (1) to execute when (2) is change (1).

This is a frequently encountered issue in Excel VBA programming when

you're developing a function with more extensive use of Userform and
controls.

OK. Let me tell you a technique to resolved this type of problem.

Consider the scenario below:
1) You got an userform.
2) There is a simple listbox
3) On Activate of userform, you want to add an item "abc" to the listbox.
4) When the form is displayed, when the user click onto the listbox item,

you want to show a msgbox.
5) On Activate of userform, you don't want the code in (4) to be executed.

Solution:
=====
1) Use the code below in the userform
2) Note the Boolean variable "changing". When setting it to TRUE, it

represent "some code is doing some changes". When FALSE, "no code is
changing anything", therefore, any change is caused by the user.

'-------------------------------------------------
Option Explicit
Dim changing As Boolean

Private Sub ListBox1_Change()
If changing = False Then
MsgBox "Listbox Change code executed!"
End If
End Sub

Private Sub UserForm_Activate()
changing = True
ListBox1.AddItem "ABC"
changing = False
End Sub
'--------------------------------------------------------



----- RADO wrote: -----

Hi all,

I am a begginer in programming Excel forms, and I ran into
an issue I don't know how to resolve. Please help!

I have a multi-selection list box, and I use "on Change"
event to do some things whenever user changes selections.
It works fine, but I have problem initializing the list.

When the form is activated, I want to restore the
selections saved when a user closed the form. So I go item
by item and set their "Selected" status according to the
status array I saved on exit. However, every time it
triggers "Change" event, and everything gets screwed.

Is there a way to turn-off the Change event while
manupulating control values programmatically? Or have the
control to react only on changes casued by the user? Or
maybe I am taking a completely wrong approach?

Thanks!
RADO



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multi-select from a dropdown list PaulaG Excel Discussion (Misc queries) 5 April 7th 10 06:52 PM
Multi Select from Drop List PatriciaT Excel Discussion (Misc queries) 2 September 8th 09 06:33 PM
how do I select multi values from a list Tommy Excel Discussion (Misc queries) 1 July 12th 06 09:38 AM
Extract values from a multi-select multi-column list-box Peter[_20_] Excel Programming 5 September 28th 03 04:04 PM
Multi Select List Box jacqui Excel Programming 0 July 22nd 03 12:12 PM


All times are GMT +1. The time now is 03:18 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"