PDA

View Full Version : Solved: Userform & enabling textboxes



blackie42
07-31-2009, 02:08 AM
Hi,

What would be code for disabling textboxes when userform activates all but the first one. Then as the the enter key is hit the next textbox enables.

thanks for any help

Jon

Bob Phillips
07-31-2009, 02:59 AM
With Me

.TextBox2.Enabled = False
.TextBox3.Enabled = False
'etc
End With

blackie42
07-31-2009, 03:29 AM
Thanks for reply

I wanted to disable all textboxes apart from the first and setfocus on TB1 as userform activates.

When the enterkey is pressed enable TB2 and setfocus and so on - so the user has to complete the boxes in a given order.

Is this possible?

thanks

davidboutche
07-31-2009, 03:41 AM
This is a bit of guess but would something like this work?

if userform.textbox1.value = "" Then
.textbox2.enabled = false
endif

Bob Phillips
07-31-2009, 04:00 AM
Thanks for reply

I wanted to disable all textboxes apart from the first and setfocus on TB1 as userform activates.

When the enterkey is pressed enable TB2 and setfocus and so on - so the user has to complete the boxes in a given order.

Is this possible?

thanks

So, can't you use the code I gave you to do that?

blackie42
07-31-2009, 04:10 AM
Sorry XLD

Doesn't the code you gave just disable all the textboxes apart from TB1 at launch?

Will it enable TB2 once TB1 has had some input and the enter key is pressed with focus then set on TB2 etc

thanks
Jon

Benzadeus
07-31-2009, 04:48 AM
Would it be something like this?

Bob Phillips
07-31-2009, 04:49 AM
I just showed you the technique. You would need to apply that to your project. To enable again when another box gets input, add a line with Enable = True in that textbox's change event.

blackie42
07-31-2009, 06:21 AM
Thanks for further explanation Bob - I've got it now. (only a very infrequent VBA coder and tend to forget the basics after a while) - I've got it now.

Thanks also to Ben - I suspect that is a much classier way of doing it but will stick to the simple way for now. May be revisit when I get more time

And thanks to David for chipping in too..

Best regards

Jon