?
Solved

Excel, VBA; OnChange event of a ComboBox

Posted on 2003-03-29
8
Medium Priority
?
7,723 Views
Last Modified: 2007-12-19
Hi there,

is it possible to temporarily disable the OnChange event of a combobox?

I have a userform with a combobox. The combobox gets its content from the
column A of my spreadsheet.

During runtime of this macro the content of the column A changes,
and unfortunately the event OnChange is launched.

I tried to avoid this problem with a code like this:

Dim ComboStatus as Boolean

Private Sub cbo_Change()
    Dim SelectedThematics As String
    Dim c As Range

If ComboStatus = True Then

' some code here

End Sub 'cbo_Change()
   
Private Sub btnSaveChanges_Click()

' Button on the same userform, together with the combobox

ComboStatus = False

' Some code here

End Sub  ' Sub btnSaveChanges_Click()

Can you please tell me, why the OnChange event is executed, whenever I click on the CommandButton,
although I tried to avoid it by using the boolean variable by setting it to status = false ?

Is there another way how I can avoid the OnChange event of the combobox?

I already tried combobox.enabled = false and combobox.locked= true,
but this does not work either.

Have you any other suggestions how my problem can be solved?

0
Comment
Question by:mathes
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 44

Expert Comment

by:bruintje
ID: 8230284
Hello Mathes,

seems no other way then to temporarely disable the box but that would be no solution ....

why not use the click event if it's only to enable the user to make a choice out the box, then the change event is empty and can be raised any time

you handle the user action in the click or buttonup event of the box

HAGD:O)Bruintje
0
 

Author Comment

by:mathes
ID: 8230346
Hi there,

thank you very much for your input.

The CommandButton does more than simply doing a selection.

After selecting from the Combobox, a dataset is copied from the spreadsheet, and displayed within several textedit controls of the userform.
Now the user can edit the dataset. When he has finished, he can click the CommandButton. Now the changes are written to the spreadsheet and the spreadsheet is updated and saved. This is the moment when unfortunately the OnChange event of the combobox is launched.

Is there a solution for my problem?
0
 
LVL 44

Expert Comment

by:bruintje
ID: 8230398
well as per above you do not need the onchange event to trigger the copy of the dataset

you can do this

Private Sub ComboBox1_Click()
'put the code in the onchangevent here
End Sub

and do not use the onchange event at all
0
Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 

Author Comment

by:mathes
ID: 8230431
Hi there,

The OnChange event is required.

After the userform has been loaded, I want that the user makes his choice. He selects the dataset to be modied by selecting one of the items of the combobox.

The CommandButton is only for saving the changes, after the user has edited the dataset, selected before. It is not the task of the CommandButton to select a dataset.
0
 
LVL 44

Accepted Solution

by:
bruintje earned 2000 total points
ID: 8230467
ok you can pickup a sample of what i meant .... the combobox HAS a click event of it's own so use that one INSTEAD of the onChange event

http://www.bredlum.com/ee_temp/xlclickcombo.xls

2 boxes one with only a different event implemented
0
 
LVL 13

Expert Comment

by:cri
ID: 8230537
Have a look into http://www.j-walk.com/ss/excel/tips/tip42.htm . If it suits you 'as is' you can use it for free, unlocking the code costs 20 USD.
0
 

Author Comment

by:mathes
ID: 8230635
Hi there,

thank you very much for your help. This is exactly what I was looking for.
0
 
LVL 44

Expert Comment

by:bruintje
ID: 8230642
:) thanks for the grade
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question