disable textboxes when conditions are met

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
2,169
Office Version
  1. 2016
Platform
  1. Windows
Hello All,
I have this challenge here: i wanna find out if what i am thinking is possible. Then after that i need help with it.

So i have a textbox called txtCurrentUser and in this textbox i have username in it. Now i wanna write a script to look at the txtCurrentUser, counting from the left to right, match the third character to another textbox's value(txtOption). If value is not the same, then disable all textboxes from Rw2 to Rw23 (these are the names of textboxes i wanna disable if names didnt match). The value in txtCurrentUser could be as:
M1Afighter
M2Bswimmer
M3Csinger
M4Dpainter
M5 fisher

But when the values are the same, then i will like to disable all but two textboxes. Say i have the username: M5 fisher then in txtOption there is blank, then disable all except two say Rw6 and Rw16. Else disable all of them.

So the A, B, C, D or Blank is what i am talking about as the third character in the txtCurrentUser. Thanks and i hope this is very clear.
Kelly

Ps.
All these controls are on a userform
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
The value of the .Enabled property should be ((i Mod 2) = 0) rather than the AND construction used above.
 
Upvote 0
The value of the .Enabled property should be ((i Mod 2) = 0) rather than the AND construction used above.
Okay thank you.

what if i want to disable like this: when the fourth character in txtCurrentUser is say "f" , i will enable only a pairs say Rw6 and Rw15. Then when txtCurrentUser contains say "p" as the 4th character, then another pair say Rw7 and Rw16 is enabled and so on?
 
Upvote 0
This is what I have tried. But I am not cool with how to use the case statement to achieve my goal. So I placed a label called CUser which takes the fourth character from the txtCurrentUser. And the code below is what I have achieved so far.
Code:
If (LCase(Mid(txtCurrentUser, 3, 1)) = LCase(Rw4.Text)) And (Mid(txtCurrentUser.Text, 4, 1)) = CUser.Caption Then
    ‘I want to use some variables here maybe. But can’t figure it out.  _
The next pair will be Rw7 and Rw16, this will go down to Rw14 and Rw23
With Rw6 And Rw15
        Select Case Mid(txtCurrentUser.Text, 4, 1)
        Case "M":
        Rw6.Enabled = True
        Rw15.Enabled = True
	‘the next pair follow down
        Case "N":
        Case "O":
        Case "P":
        Case "Q":
        Case "R":
        Case "S":
        Case "T":
        Case "U":
        End Select
End With
    Else
    MsgBox "I am cooler"
    End If
 
Upvote 0
Code:
With Rw6 And Rw15
I'm curious about this line. What are Rw6 and Rw15. If they are text boxes, I can't see how that line compiles.
 
Upvote 0
Yes they are textboxes. And like i said earlier, i am not cool with this case staments and the with stuff thats why i got stacked. So i wannaa use the case to do the switching. If case"m" then turn two textboxes on . If case"n" then turn another two on and so on.
Oh okay maybe this:
Code:
Select Case Mid(txtCurrentUser.Text, 4, 1)
        Case "M":
        Rw6.Enabled = True
        Rw15.Enabled = True
	‘the next pair follow down
        Case "N":
        Case "O":
        Case "P":
        Case "Q":
        Case "R":
        Case "S":
        Case "T":
        Case "U":
        End Select
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,265
Members
452,627
Latest member
KitkatToby

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top