Link to home
Start Free TrialLog in
Avatar of SteveL13
SteveL13Flag for United States of America

asked on

All object on a tab disabled but can I change the forecolor?

I have a tab on a form disabled but what the forecolor to be black.  Is there a way to do this without having to code a separate line for each object on the tab?

I've tried this but it doesn't work:

    If DBEngine.Workspaces(0).Users(CurrentUser).Name = "Shop" Then
        Me.Casting.Enabled = False
        Me.Casting.ForeColor = vbBlack
    End If
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Try this:

If DBEngine.Workspaces(0).Users(CurrentUser).Name = "Shop" Then
        Me.Casting.Enabled = False
        Me.Casting.Locked = true
    End If

Open in new window

but what the forecolor to be black.
What forecolor do you want to change? A TabPage doesn't have a ForeColor property.

You can loop through the Controls collection of the TabPage's controls:

Dim ctl As Control

On Error Resume Next
For each ctl in Me.MyTabPage.Controls
  ctl.Forecolor = vbBlack
Next
>> TabPage doesn't have a ForeColor property.

Ah... I was assuming that "Casting" was a textbox or other control.

With a Textbox,  Locked = True/Enabled = false will prevent data modifications, but leave the text color unchanged (it won't take on the 'disabled' look).
Avatar of SteveL13

ASKER

Here is what I have so far but the forecolor is still grayed out and I need it to be black on each object on the tab of the form.

    Dim ctl As Control

    If DBEngine.Workspaces(0).Users(CurrentUser).Name = "Shop" Then
        Me.Casting.Enabled = False
        On Error Resume Next
        For Each ctl In Me.Casting.Controls
        ctl.ForeColor = vbBlack
        Next

??
By the way. the code is on the onopen event of the form.  I assume that is where it should be, right?
ASKER CERTIFIED SOLUTION
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
For some reason when I used:

    If DBEngine.Workspaces(0).Users(CurrentUser).Name = "Shop" Then
        Me.Casting.Enabled = False
        Me.Casting.Locked = True
        On Error Resume Next
        For Each ctl In Me.Casting.Controls
        ctl.ForeColor = vbBlack
        Next

the form wouldn't open.

So I tried:

        On Error Resume Next
        For Each ctl In Me.Casting.Controls
          ctl.ForeColor = vbBlack
          ctl.Locked = True
          ctl.Enabled = False
        Next

And it worked!  Thanks.