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
SteveL13Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mbizupCommented:
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

0
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
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
0
mbizupCommented:
>> 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).
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

SteveL13Author Commented:
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

??
0
SteveL13Author Commented:
By the way. the code is on the onopen event of the form.  I assume that is where it should be, right?
0
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
as mbizup suggested earlier, set Locked = True in addition to Enabled = False.

    Dim ctl As Control

    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

If that doesn't work, then DON'T set Casting to Enabled or Locked, and instead set each control on the TabPage:

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SteveL13Author Commented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.