Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable A Group of Controls

Status
Not open for further replies.

RiderJon

Programmer
Aug 26, 2002
190
FR
Hello all:

Is there a quick way to disable a group of text boxes. By disable I mean make it "grayish" with no way to enter values. Note: I am NOT talking about Making it Visibile/Invisible using the "controls.visible" property.

What I WANT TO DO:
Select Region is a drop-down menu with say "Region1, Region2". If I select Region1, then I want to "disable" the textboxes under Region2.

Select Region: ____________


REGION 1: Total Expected
Bates1 _____ ________
Bates2 _____ ________
Bates3 _____ ________
Bates4 _____ ________
REGION 2:
Bates1 _____ ________
Bates2 _____ ________
Bates3 _____ ________
Bates4 _____ ________

FINALLY:
I have 10-15 controls under each region. Is there a quickly way to enable/diable them in groups. I have tried to create a rectangular box over each region that is made "Visible/Invisible" based on the "Select Region Value". It serves my purpose but it looks ugly to have blanks when you select say Region 2.

I hope I was clear, if not, please shoot back with questions.

THANK YOU.





RiderJon
"I might have created ctrl+alt+del,
But Bill made it famous" - Dr. Dave
 
What you need to use is Control1.Enabled = False

I think this works on most Access controls

Thanks
GTLoco
 
I don't believe you can dis/enable them as a group. I would use somekind of naming convention for the control names. Then you could loop thru the appropriate controls to dis/enable them.

For example, for Region1, add a suffix to the names of all of the controls that relate to that region (i.e. txtRegion1_1,txtRegion1_2...txtRegion1_15). Now, if you want to dis/enable the controls for region 1, then do something like this:

Dim bolEnable As Boolean
Dim intRegion as Integer

intRegion = 1

if (whatever) then bolEnable = true else bolEnable = False

For i = 1 to 15
Me("txtRegion" & intRegion & "_" & i).enabled = bolEnable
Next i
 
Okie ....

It's weird or it's friday.

I got the Enabled thing to work. Thank you. But it confuses me:

when I say True -> it is disabled
when I say False -> it is enabled?

RiderJon
"I might have created ctrl+alt+del,
But Bill made it famous" - Dr. Dave
 
enabled = True should enable the control, False disables it. That is how it should work anyway. Have never realy used it ;)

GTLoco
 
Create two procedures (E.g. disableRegion1, disableRegion2). In each procedure disable the appropriate textboxes. Call the appropriate procedure based on the drop-down menu selection made by the user,

For example (pseudo-code):

Private Sub selectRegion_Change()
select case selectRegion
case "Region 1"
call disableRegion1()
case "Region 2"
call disableRegion2()
end select
End Sub

Private Sub disableRegion1
me.bates1Region1.enabled = False
me.bates2Region1.enabled = False
...
me.bates4Region1.enabled = False
me.bates1Region2.enabled = True
me.bates2Region2.enabled = True
...
me.bates4Region2.enabled = True
End Sub

Private Sub disableRegion2
me.bates1Region1.enabled = True
me.bates2Region1.enabled = True
...
me.bates4Region1.enabled = True
me.bates1Region2.enabled = False
me.bates2Region2.enabled = False
...
me.bates4Region2.enabled = False
End Sub
 
Thank you Scoff and Fancy. That will be helpful next time: my naming isn't logically for now.

GTloco:
It's definitely friday: I saved and reopened it and now it worked the other way. So switched the true/false and it works like we expect on most days.

Another question:
Can I call a "sub" that is located in the subfrm. I even made the "sub" public.

'located in sub form subfrmDemo
Public Sub ChangeColor()

.......

End Sub


in the main form I call it:

subfrmDemo.ChangeColor

Any suggestions. Thank you all.


RiderJon
"I might have created ctrl+alt+del,
But Bill made it famous" - Dr. Dave
 
I would create a module with your sub code in it and call that instead. Calling anything from a subform can get hairy.

GTLoco
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top