Disabled Enabled

  • Thread starter Thread starter Garry Jones
  • Start date Start date
G

Garry Jones

I have a problem with Enabled=True

I have 18 textboxes. All prefilled with suggested values.

Textbox1 opens first. All other textboxes are now Enabled=False so user
can not use mouse and jump randomly. User can enter another value in
textbox1 and press tab or accept suggested value by just pressing tab.

When user tries to leave textbox1 I trap it with the Textbox1.Exit
control (and I also use "before update" to reset to if new value not
allowed) and compare the new value to other values. If it is accepted by
my compare I allow the user to leave Textbox1 and I place the user in
Textbox2.

But to do this I have to set Enabled=True for Textbox2. So if the input
in Textbox1 is okay I have to set Enabled=True for Textbox2. This is the
bit that isn't working. When the code runs that sets Enabled = True for
Textbox2 it then thinks the user has left textbox2 and it runs the Exit
check for Textbox2 and moves on to Textbox3 and so on. The entire
proceedure runs through to Textbox18

There are probably other ways to do this, but before I change all the
code and have a rethink I wonder if anyone knows a way to stop the use
of Enabled from triggering the Exit feature.

Garry Jones
Sweden
 
Hi,

I would advise to include some code to temporarily disable
the events from firing.

- At the top of the form's module (in what is known as the
declaration section) type:

Dim bDisableEvents as Boolean

Now in each event sub that needs it:

Private sub WhateverControl_Click()
If bDisableEvents Then Exit sub
bDisableEvents=True
'Your code
bDisableEvents=False
End Sub

Regards,

Jan Karel Pieterse
Excel TA/MVP
 
Back
Top