Events firing willy nilly
[Excel2000]
I have a form with a number of comboboxes and listboxes on it. Some of these controls change the values of other controls, causing their events to trigger. I want to stop this in some cases. Has anyone got any suggestions? For example, cmbName is changed, and this changes everything else including cmbType. But cmbType has a macro that I only want to run when cmbType is manually changed, but not when its value is changed by another event. Is it possible to achieve this? TIA Darren |
Events firing willy nilly
You would probably need to set a global flag to determine how the control is
being changed. It could get pretty cumbersome with multiple controls. Here's some untested pseudocode: Dim fSwitch As Boolean Sub cmbName_Change() fSwitch = True 'make changes to cmbType fSwitch = False End Sub Sub cmbType_Change() If fSwitch = True Then Exit Sub 'your code here End Sub You get the idea. -- Vasant "Darren Hill" wrote in message ... [Excel2000] I have a form with a number of comboboxes and listboxes on it. Some of these controls change the values of other controls, causing their events to trigger. I want to stop this in some cases. Has anyone got any suggestions? For example, cmbName is changed, and this changes everything else including cmbType. But cmbType has a macro that I only want to run when cmbType is manually changed, but not when its value is changed by another event. Is it possible to achieve this? TIA Darren |
Events firing willy nilly
Darren,
I don't know of any "disable control events" parameter. One way is to have a global Boolean variable which tells other events whether something's already going on. eg. Private i As Long Private blnExecuting As Boolean Private Sub TextBox1_Change() If blnExecuting Then Exit Sub blnExecuting = True i = i + 1 TextBox2.Text = Left(TextBox1.Text, 1) & i blnExecuting = False End Sub Private Sub TextBox2_Change() If blnExecuting Then Exit Sub blnExecuting = True i = i + 1 TextBox1.Text = Left(TextBox2.Text, 1) & i blnExecuting = False End Sub Rob "Darren Hill" wrote in message ... [Excel2000] I have a form with a number of comboboxes and listboxes on it. Some of these controls change the values of other controls, causing their events to trigger. I want to stop this in some cases. Has anyone got any suggestions? For example, cmbName is changed, and this changes everything else including cmbType. But cmbType has a macro that I only want to run when cmbType is manually changed, but not when its value is changed by another event. Is it possible to achieve this? TIA Darren |
Events firing willy nilly
Thanks Rob and Vasant, I'll try that.
-- Darren |
Events firing willy nilly
Update: thanks again, Vasant and Rob. I've got the global variable method
working - whew! Darren |
All times are GMT +1. The time now is 07:17 PM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com