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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to disable all but one control.

Status
Not open for further replies.

bipeman

Technical User
Nov 20, 2001
9
US
I need to disable all controls except one checkbox on my form (and subforms) depending on the condition of another checkbox. I have tried looping through the controls collection as follows:

dim ctl as control
For Each ctl in Me.Controls
Me.Ctl.Enabled = False
Next ctl

Then I planned to re-enable the checkbox I need as follows:

Me.CkNeeded.Enabled = True (Which works)

But of course Access does not allow me to refer to the "enabled" property when using a variable as the control name. I have tried some different syntax to no avail.

Any help will be much appreciated! Thanks in advance!

Mike
 
bipeman,

You said ANY help! [bigsmile]

I found some code on a newsgroup recently that enabled me to set BackColor and SpecialEffect properties in VBA. The strange thing is the syntax used. It does work and perhaps may be of use to you with the Disable property.

Dim idx As Integer
Dim lblName As String

idx = 1
Do Until idx > OsubG_Count
lblName = "lbl_" & idx
Me(lblName).BackColor = 16776960 'light blue
Me(lblName).SpecialEffect = 4 'shadowed
idx = idx + 1
Loop
Regards, Sorrells
 
Hello

I would try this :

dim ctl as control
For Each ctl in Me.Controls
if me.ctl.name <> me.CkNeeded.name then
Me.Ctl.Enabled = False
endif
Next ctl

Hope this help,
Yvon Duvivier
 
Thanks Sorrells, I got a couple ideas from your suggestion but didn't work.

Duvy... the problem is the the lin &quot;Me.ctl.enabled = false&quot; won't work. It does not seem to replace &quot;ctl&quot; with the value.

I am beginning to think I may need to read all the control names into an array first, then create a string with values pulled from the array. I also think that this may be way overcomplicating things! (My usual approach!)

Mike
 
bipeman,

I have not used the control colletion (am I refering to it correctly?) but wonder if you know that you are starting at the first control. If the line that performs the 'enable' works correctly then one would think the syntax in the loop would be correct as well. Especially if you are receiving no error.

Can you force Access to be at the first control and then make your FOR loop dependend on EOF?

Regards, Sorrells
 
Check with this sample and it work:

If ctl.ControlType = acTextBox Then
' Define control properties.
With ctl
.SetFocus
.Enabled = True
.Height = 400
.SpecialEffect = 0
End With
End If
However, this is only for textbox.

Regards,
Yvon
 
Thanks Duvy! Your code brought me to the root of my problem. By failing to specify the control type, as soon as my code hit a control that does not support the Enabled property ( Label ) it errored out.

Best to all!

Mike
 
I second that! This will help me in my current project. Good show! [2thumbsup] Regards, Sorrells
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top