Disable Controls on Form

karmahum

Registered User.
Local time
Today, 21:50
Joined
Apr 29, 2002
Messages
53
Hello all.

Depending on the logged used I would like to disable every textbox and combobox on a form using VBA. I know that I can use the following code to move through the Control Collection:

Dim ctr As Control

For Each ctr In Me.Controls
DO SOMETHING HERE
Next ctr
'
Me.Refresh

However, the form obviously has other controls (i.e. Labels) that do not have an ENABLE property.

Is there a way to check what type of control each is and only disable the appropriate one?

Thanks in advance,
Sean
 
If you HIDE [.Visible = False] the control then it's label will also be hidden.
 
ghudson said:
If you HIDE [.Visible = False] the control then it's label will also be hidden.

Thanks for the reply.

My intent is to disable the controls so that the user can still view the information...But not make any changes. Any ideas??

Thanks.
 
Last edited:
Why not just use Me.AllowEdits=False etc, or better still just open the form in read only mode depending on the user?
 
Code:
For Each ctrl In frmActiveForm
      If ctrl.ControlType = acCommandButton Then
        If Not ctrl.Tag = "keep" Then
          ctrl.Enabled = True
        End If
       End If
     Next

You can make it say actextbox etc etc etc and it will do the same thing. I have some command buttons that I need enabled and some that do not. So, I use this code and type keep into the tag feild of any ones that I dont want disabled dynamically. Only issue is you cant disable a ctrl if it has focus so be aware of that. Hope this helps.
 
Follow-Up

Pat Hartman said:
You can identify the control type as you are looping through the connection. Then you can bypass the labels.

First of all, thanks all for the responses.

Pat, can you give me some help with identifying the control type. That is what I was looking for, however, I am not sure about the logic to do so.

Thanks again!
 
Did you try FloBobs code listed above. All objects have a "Tag" property and that should do what you want.
 

Users who are viewing this thread

Back
Top Bottom