Greying out specific boxes based on a selection made

PrettyMess

Board Regular
Joined
Feb 10, 2015
Messages
66
Is there anyway to grey out specific boxes using the following code however I only want to use two parameters (Cancellation List and Ported) all other options the users select from the drop down I would like them to have to fill out all information.

I can get it to grey out the relevant boxes but it doesn't apply that I only want this done for Cancellation List.

I know I could do this for each of the options in the drop down but I have close to 50 options so I don't really want to use that method.

Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)

Select Case Me.Combo128.Value

Case Is = "Cancellation List"
Me.MobileNumber.Enabled = False
Me.Mobex.Enabled = False
Me.UserName.Enabled = False
Me.Text130.Enabled = False
Me.Text126.Enabled = False
Me.Check123.Enabled = False
Me.Text9.Enabled = False
Me.Text49.Enabled = False
Me.Check134.Enabled = False
Me.Check138.Enabled = False

End Select

End Sub

Private Sub TypeList_AfterUpdate()

Select Case Me.Combo128.Value

Case Is = "Cancellation List"
Me.MobileNumber.Enabled = False
Me.Mobex.Enabled = False
Me.UserName.Enabled = False
Me.Text130.Enabled = False
Me.Text126.Enabled = False
Me.Check123.Enabled = False
Me.Text9.Enabled = False
Me.Text49.Enabled = False
Me.Check134.Enabled = False
Me.Check138.Enabled = False

End Select

End Sub

Any help would be greatly appreciated
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Not real sure of what you're doing or are saying. I see no parameters. I see a select block with only one case (odd). I see what you want for Cancellation but not Ported. I wonder why you'd say you can do this for 50 options when you only want it for two (Cancellation and Ported).
So assuming you want the same controls disabled if either of two options are selected, use an If block
If Me.combo128 = "Cancellation" OR Me.combo128 = "Ported" Then
code to disable controls
End If
Based on your post, I only see this having to be written once (because there only seems to be one combo involved). I might not put this in the BeforeUpdate on the form. If there was an error in the update, you could find some disabled and some not. A better spot might be the AfterUdate event for the form or even the combo you're checking.
 
Upvote 0
I still cant get this to work with making these changes - If I only put it in after update it doesn't grey out anything and if I put it into before update and after update it greys out everything no matter what option is selected.

To try and explain it better I have a drop down (combo Box) in my form that if a user selects the option "Cancellation List" I would like all other text boxes on the screen to be greyed out, the same applies if they select the drop down option for ported.

But if they select any of the 50 other options from the drop down box I would like these to remain normal so they user has to fill them in.

I have used this else where in my database but I cant seem to get the one on this form to work at all, the only difference is in another form I used a case statement but as there where only five options the users could select from I didn't mind writing out the code for each selection but I don't want to have to do this for 50 in my new form.

Any help would be greatly appreciated.

Thanks
Paula
 
Upvote 0
I see (I think). Put this in the AfterUpdate event
Code:
Dim ctl As Control

If Me.combo128 = "Cancellation" OR Me.combo128 = "Ported" Then
 For each ctl in Me.Controls
   If ctl.Type=acTextbox Then ctl.Enabled = False
 Next
End If
If that doesn't work, I suspect you have a multi-column combo, and in code, you are not dealing with the column you think you are. How it works in the BeforeUpdate makes sense. Why it doesn't in the AfterUpdate is unknown. You should try to provide more info about what's going on by stepping through your code and stating what conditions are encountered or what the value of variables are.

If you're in the mood to learn, take a look at Access naming conventions (and for sure, reserved words). When you have 15 names like Text12 and you are trying to trouble shoot 100 lines of code down, Text11 doesn't mean much.

Edit: If a user makes a mistake, you have no means of putting them back to enabled. Suggest you add a way to reverse it.
Dim ctl As Control

Code:
If Me.combo128 = "Cancellation" OR Me.combo128 = "Ported" Then
 For each ctl in Me.Controls
   If ctl.Type = acTextbox Then ctl.Enabled = False
 Next
Else
 For each ctl in Me.Controls
  If ctl.Type = acTextbox Then ctl.Enabled = True
 Next
End If
 
Last edited:
Upvote 0
I couldn't get this to work either so I ended up resorting to the longer method, I'm pretty sure there has to be an easier way of doing this but hey if it works.
Thanks for all your help.
Code:
Private Sub DeptCode_AfterUpdate()
Select Case Me.DeptCode.Value

Case Is = "Cancellation List"
Me.MobileNumber.Enabled = False
Me.Mobex.Enabled = False
Me.UserName.Enabled = False
Me.Text130.Enabled = False
Me.Text126.Enabled = False
Me.Check123.Enabled = False
Me.Text9.Enabled = False
Me.Text49.Enabled = False
Me.Check134.Enabled = False
Me.Check138.Enabled = False
Me.Text15.Enabled = False
Me.Text17.Enabled = False
Me.Text19.Enabled = False
Me.Text21.Enabled = False
Me.Text23.Enabled = False
Me.Text27.Enabled = False
Me.Text29.Enabled = False
Me.Check11.Enabled = False
Me.Text91.Enabled = False
Me.Text97.Enabled = False
Me.Combo115.Enabled = False
Me.Combo117.Enabled = False
Me.Combo119.Enabled = False
Me.Combo121.Enabled = False
Me.Check81.Enabled = False
Me.Check83.Enabled = False
Me.Check85.Enabled = False
Me.Check87.Enabled = False
Case Is = "Ported"
Me.MobileNumber.Enabled = False
Me.Mobex.Enabled = False
Me.UserName.Enabled = False
Me.Text130.Enabled = False
Me.Text126.Enabled = False
Me.Check123.Enabled = False
Me.Text9.Enabled = False
Me.Text49.Enabled = False
Me.Check134.Enabled = False
Me.Check138.Enabled = False
Me.Text15.Enabled = False
Me.Text17.Enabled = False
Me.Text19.Enabled = False
Me.Text21.Enabled = False
Me.Text23.Enabled = False
Me.Text27.Enabled = False
Me.Text29.Enabled = False
Me.Check11.Enabled = False
Me.Text91.Enabled = False
Me.Text97.Enabled = False
Me.Combo115.Enabled = False
Me.Combo117.Enabled = False
Me.Combo119.Enabled = False
Me.Combo121.Enabled = False
Me.Check81.Enabled = False
Me.Check83.Enabled = False
Me.Check85.Enabled = False
Me.Check87.Enabled = False
Case Else
Me.MobileNumber.Enabled = True
Me.Mobex.Enabled = True
Me.UserName.Enabled = True
Me.Text130.Enabled = True
Me.Text126.Enabled = True
Me.Check123.Enabled = True
Me.Text9.Enabled = True
Me.Text49.Enabled = True
Me.Check134.Enabled = True
Me.Check138.Enabled = True
Me.Text15.Enabled = True
Me.Text17.Enabled = True
Me.Text19.Enabled = True
Me.Text21.Enabled = True
Me.Text23.Enabled = True
Me.Text27.Enabled = True
Me.Text29.Enabled = True
Me.Check11.Enabled = True
Me.Text91.Enabled = True
Me.Text97.Enabled = True
Me.Combo115.Enabled = True
Me.Combo117.Enabled = True
Me.Combo119.Enabled = True
Me.Combo121.Enabled = True
Me.Check81.Enabled = True
Me.Check83.Enabled = True
Me.Check85.Enabled = True
Me.Check87.Enabled = True
 End Select


End Sub
 
Upvote 0
I couldn't get this to work either so I ended up resorting to the longer method, I'm pretty sure there has to be an easier way of doing this but hey if it works.

You're right, there is an easier way. What I posted is how I've done it many times, including disabling only certain controls within a type group based on their tag value. If you needed other types besides acTextbox, all you'd have to do is include those types in the IF block. Note item #1 in my signature - did you make any of the required declarations - like Dim ctl As Control ?
 
Upvote 0

Forum statistics

Threads
1,214,952
Messages
6,122,454
Members
449,083
Latest member
Ava19

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