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

Disable/Enable controls in Access XP 1

Status
Not open for further replies.

Cads

Technical User
Jan 17, 2000
40
GB
Don't know if anyone's had a simlar problem when migrating from 97 to XP but the following code (lifted from the popular 'Solutions' database, once available from MS as a download) won't work in XP. The code seems to loop indefinitely on first accessing and then it subsequently throws up an error at 'ctl.Enabled', saying the property is not supported.

It's called from 'EnableControls Me, acDetail, true' in the VBA of a form.

Function EnableControls(frm As Form, intSection As Integer, intState As Boolean) As Boolean

Dim ctl As Control

' Set intState for all controls in specified section.
For Each ctl In frm.Controls
If ctl.Section = intSection Then
On Error Resume Next
ctl.Enabled = intState
Err = 0
End If
Next ctl

EnableControls = True

End Function

Any advice would be greatly appreciated as I've wasted many brain cells trying to solve it so far!


Steve House
shouse@icaew.co.uk
 
Perhaps not all controls have enabled property?

Perhaps have a look at the following faq for some different methods faq702-5010, with an explanation and samples of how to only loop relevant controls, and also a brief explanation on only looping controls in a particular sections.

Roy-Vidar
 
Thanks for your FAQ. I changed the code to only select controls that can be enabled/disabled.

Still not sure why the 'On error resume next' doesn't cater for non-enable controls, nor why the list of properties for a control (eg ctl.) doesn't list 'enabled' or 'controltype', but sometimes you have to just accept these apparent anomalies if you find a solution and be grateful for that!
 
I don't know. Does Err = 0 clear the error object?

Perhaps clearing it through something like this works better?

[tt]On Error Resume Next
ctl.Enabled = intState
if err.number <> 0 then
err.clear
end if[/tt]

ctl - or control - is a generic reference that could match, or be assigned, all kinds of controls. Some controls have a value property, others don't, some have a rowsource property others don't... Had it been declared as textbox, or some other explicit control, more of the properties would probably be exposed through the intellisence, but then one wouldn't have the opportunity of such methods as above;-)

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top