Diable a group of objects

A

alex

Using Access ’03…

What would be the best way to disable all objects on a form except a
few chosen dynamically?

I have form/switchboard that opens when a user accesses the db.
Depending on who the user is (their loginID contained in a linked
table), I want to enable/disable objects on the form.

I’m sure it could do it individually, but it would be nice if I could
assign a bunch of objects to a group and then disable/enable that
group.

E.g.,
Dim N as object
N in (
Object 1
Object 2)

Thoughts?
alex
 
D

Dirk Goldgar

I usually use the Tag property of the controls to identify them as belonging
in a particular group. You can put anything you want in the Tag property,
and then reference it in code. For example:

'----- start of example code -----
Function EnableDisable(blnEnabled As Boolean)

Dim ctl As Access.Control

For Each ctl In Me.Controls

If ctl.Tag = "EnableDisable" Then

' Guard against attempting to disable focused control.
If blnEnabled = False Then
On Error Resume Next
If Me.ActiveControl.Name = ctl.Name Then
Me.SomeSafeControl.SetFocus
'*** Substitute the name of some other control
'*** for "SomeSafeControl".
End If
End If

' Enable or disable the control as directed.
ctl.Enabled = blnEnabled

End If

Next ctl

End Function
'----- end of example code -----

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


Using Access ’03…

What would be the best way to disable all objects on a form except a
few chosen dynamically?

I have form/switchboard that opens when a user accesses the db.
Depending on who the user is (their loginID contained in a linked
table), I want to enable/disable objects on the form.

I’m sure it could do it individually, but it would be nice if I could
assign a bunch of objects to a group and then disable/enable that
group.

E.g.,
Dim N as object
N in (
Object 1
Object 2)

Thoughts?
alex
 
A

alex

I usually use the Tag property of the controls to identify them as belonging
in a particular group.  You can put anything you want in the Tag property,
and then reference it in code.  For example:

'----- start of example code -----
Function EnableDisable(blnEnabled As Boolean)

    Dim ctl As Access.Control

    For Each ctl In Me.Controls

        If ctl.Tag = "EnableDisable" Then

            ' Guard against attempting to disable focused control.
            If blnEnabled = False Then
                On Error Resume Next
                If Me.ActiveControl.Name = ctl.Name Then
                    Me.SomeSafeControl.SetFocus
                    '*** Substitute the name of some other control
                    '*** for "SomeSafeControl".
                End If
            End If

            ' Enable or disable the control as directed.
            ctl.Enabled = blnEnabled

        End If

    Next ctl

End Function
'----- end of example code -----

--
Dirk Goldgar, MS Access MVPwww.datagnostics.com

(please reply to the newsgroup)


Using Access ’03…

What would be the best way to disable all objects on a form except a
few chosen dynamically?

I have form/switchboard that opens when a user accesses the db.
Depending on who the user is (their loginID contained in a linked
table), I want to enable/disable objects on the form.

I’m sure it could do it individually, but it would be nice if I could
assign a bunch of objects to a group and then disable/enable that
group.

E.g.,
Dim N as object
N in (
Object 1
Object 2)

Thoughts?
alex

Thanks Dirk. That's a great idea.
....what do you mean by: 'Guard against attempting to disable focused
control.
How could a disabled control get the focus in the first place?
alex
 
D

Dirk Goldgar

alex said:
Thanks Dirk. That's a great idea.
...what do you mean by: 'Guard against attempting to disable focused
control.
How could a disabled control get the focus in the first place?


A disabled control couldn't, but an enabled control might have the focus.
If you then attempt to disable that control, you won't be able to -- you'll
get an error along the lines of "You can't disable the control that has the
focus". So if you want to disable that control, you must first move the
focus to some other control enabled (and visible) control.
 
A

alex

A disabled control couldn't, but an enabled control might have the focus.
If you then attempt to disable that control, you won't be able to -- you'll
get an error along the lines of "You can't disable the control that has the
focus".  So if you want to disable that control, you must first move the
focus to some other control enabled (and visible) control.

Now I get it, thanks.
alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top