Solved

Disable all controls on a tab control except one dropdown on open

Posted on 2006-07-19
11
377 Views
Last Modified: 2008-09-03
I have a form with a tab control on it.  On open I would like to have everything on the tabctl disabled (if applicable) with only one combo box enabled.  thanks in advance
0
Comment
Question by:H-SC
  • 4
  • 3
  • 3
  • +1
11 Comments
 
LVL 65

Expert Comment

by:Jim Horn
Comment Utility
The quick-and-dirty approach would be to mark them all as Enabled = No (Visible = No?) in Form Design, with your one combo box Visible = Yes, then save.  
That way, on open they're all disabled, and you can write code in your combo box's AfterUpdate event to make them Enabled = Yes.

Hope this helps.
-Jim
0
 
LVL 65

Accepted Solution

by:
rockiroads earned 125 total points
Comment Utility
Way to do it in code is like this
I recommend putting it in a function so u can toggle


private sub EnableDisableControls(byval bEnable as boolean)

dim ctl as control

for each ctl in Me.Controls
    if ctl.ControlType = acTextBox or ctl.ControlType = acComboBox or ctl.ControlType = acListBox then
        if ctl.Name <> "mycombo" then
            ctl.Enabled = bEnable
        endif
    end if
next ctl

end sub


Now u call it passing in TRUE to enable, FALSE to disable

on your form_open, u can call this procedure passing in FALSE
   
0
 
LVL 1

Author Comment

by:H-SC
Comment Utility
jim,

In most cases I do just that.  In this case, I would really like to have code that does the switch for all with the one exception.  This particular form has a ton of fields and controls on it thus... looking for some type of shortcut approach to this particular form.
0
 
LVL 1

Author Comment

by:H-SC
Comment Utility
rockiroads,

thanks,

I will try...
0
 
LVL 65

Expert Comment

by:rockiroads
Comment Utility
In that code I only check for textboxes, listboxes and dropdowns

If u have other editable controls, ensure u add them in,
checkbox is acCheckBox

if u want command buttons disabled,  then its acCommandButton


Ensure u set  "mycombo"  to be the control name of your combo that u want always enabled
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 44

Expert Comment

by:Leigh Purvis
Comment Utility
Well, if you're only wanting to disable controls on the tab then surely you'd have to consider it separately from Me.Controls

Something like

    Dim ctl As Control
    Dim intPages As Integer
   
    For intPages = 0 To Me.TabControl.Pages.Count - 1
        For Each ctl In Me.TabControl.Pages(intPages).Controls
            ctl.Enabled = False
        Next
    Next

Or to use Rocki's method with a small alteration

for each ctl in Me.Controls
    if ctl.ControlType = acTextBox or ctl.ControlType = acComboBox or ctl.ControlType = acListBox then
        if ctl.Name <> "mycombo" and ctl.Parent.Name = "TabControlName" then '<<---change here
            ctl.Enabled = bEnable
        endif
    end if
next ctl
0
 
LVL 1

Author Comment

by:H-SC
Comment Utility
rockiroads,

that worked perfect !!

many thanks
0
 
LVL 65

Expert Comment

by:rockiroads
Comment Utility
No probs
0
 
LVL 44

Expert Comment

by:Leigh Purvis
Comment Utility
Were all the controls you have on that form on your tab anyway? :-p

(But you perhaps imagined that the tab control makes a difference - a bit like a subform perhaps?  I believe that is a common assumption).
0
 
LVL 65

Expert Comment

by:rockiroads
Comment Utility
Leigh u up l8, I still aint recovered, still serious sore throat but at least no fever anymore but cant find a car :(
laters mate, bedtime!
0
 
LVL 44

Expert Comment

by:Leigh Purvis
Comment Utility
Late?  This is where my day just gets going ;-)
Hours of work ahead of me yet :-D
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now