Go Back   Access World Forums > Microsoft Access Reference > Sample Databases

 
Reply
 
Thread Tools Rating: Thread Rating: 4 votes, 4.50 average. Display Modes
Old 04-27-2017, 04:48 AM   #1
isladogs
Part time moderator
 
isladogs's Avatar
 
Join Date: Jan 2017
Location: Somerset, UK
Posts: 6,615
Thanks: 90
Thanked 1,620 Times in 1,509 Posts
isladogs is just really nice isladogs is just really nice isladogs is just really nice isladogs is just really nice isladogs is just really nice
Set a group of controls as visible/hidden, enabled/disabled or locked/unlocked

The attached utility demonstrates a way of setting the state of a group of controls at the same time using the controls' Tag property.

The properties that can be controlled are: .Visible , .Enabled, .Locked

However, some control types do not allow all of the properties.
For example labels can not be disabled or locked

For full details of control types & properties, see the table tblControlTypes

All the controls in the 2 forms have tags A, B, C or D.
Use the buttons to control the state of those with tags A, B, C
To ensure the form remains usable, controls with tag D remain visible, enabled & unlocked at all times!

The forms aren't intended to be elegant, just to show what can be done



UPDATED 29/04/2017:
For portability, all the functionality is now included in the module modControlState.
There are 3 procedures: ShowControls, EnableControls & LockControls

2 forms have been included - identical apart from colour
This is just to confirm that the forms are controlled independently as you would expect

To use this approach, just copy the module modControlState to your own project


An alternative approach suggested by Static & using parameter arrays rather than tags is listed in Module1 but has not been used here
Attached Images
File Type: png SetControls.PNG (71.7 KB, 1310 views)
Attached Files
File Type: accdb SetControls - v2.accdb (864.0 KB, 546 views)

__________________
If this answer has helped, please click the Thanks button and/or click the 'reputation scales' symbol on the left.

Web links:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Colin
Previously known as ridders : Access 2010 32-bit, Access 2016 32-bit & 64-bit, SQL Server Express 2014, Windows 10,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Last edited by isladogs; 05-21-2017 at 09:37 AM. Reason: Added inline image
isladogs is offline   Reply With Quote
The Following 5 Users Say Thank You to isladogs For This Useful Post:
GK in the UK (04-08-2018), gleesonc (07-05-2017), MrHans (04-27-2017), Tupacmoche (05-11-2018), usm01 (07-25-2017)
Old 04-01-2018, 08:55 AM   #2
Smokeeater
Newly Registered User
 
Join Date: Jan 2009
Location: Indiana
Posts: 42
Thanks: 8
Thanked 0 Times in 0 Posts
Smokeeater is on a distinguished road
Re: Set a group of controls as visible/hidden, enabled/disabled or locked/unlocked

Ridders, thank you for the reply. I would prefer to not tie these back to a tag on a control. The end user will unhide a large number of fields all at once, based on need. If not needed, them all of them in the module will stay hidden. If they are needed, I see them using a button to unhide the controls.

I may just have to keep the code tied to a command button if a module cannot be used.
Smokeeater is offline   Reply With Quote
Old 06-13-2018, 05:18 AM   #3
isladogs
Part time moderator
 
isladogs's Avatar
 
Join Date: Jan 2017
Location: Somerset, UK
Posts: 6,615
Thanks: 90
Thanked 1,620 Times in 1,509 Posts
isladogs is just really nice isladogs is just really nice isladogs is just really nice isladogs is just really nice isladogs is just really nice
Re: Set a group of controls as visible/hidden, enabled/disabled or locked/unlocked

Smokeeater
You referred to my reply but as your post has only just been approved, I can't remember if this was done via a PM.

To my mind this approach is perfectly suited to what you describe.
Users can click a button to show additional controls if that's what you want... However, normally I just build that into the code as needed

For example:
a) admin user logged in - show additional controls
b) user clicks Yes on a combo / option group => items shown are updated
etc, etc

__________________
If this answer has helped, please click the Thanks button and/or click the 'reputation scales' symbol on the left.

Web links:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Colin
Previously known as ridders : Access 2010 32-bit, Access 2016 32-bit & 64-bit, SQL Server Express 2014, Windows 10,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
isladogs is offline   Reply With Quote
Old 06-13-2018, 11:44 PM   #4
Smokeeater
Newly Registered User
 
Join Date: Jan 2009
Location: Indiana
Posts: 42
Thanks: 8
Thanked 0 Times in 0 Posts
Smokeeater is on a distinguished road
Re: Set a group of controls as visible/hidden, enabled/disabled or locked/unlocked

Ridders,

Thank you for following up. All of the changes have been made and the end users are really satisfied with the hidden fields, and unhiding them with the buttons. I also threw in a couple other minor changes to splash it up a little. On to the next challenge!
Smokeeater is offline   Reply With Quote
Old 06-14-2018, 08:15 AM   #5
isladogs
Part time moderator
 
isladogs's Avatar
 
Join Date: Jan 2017
Location: Somerset, UK
Posts: 6,615
Thanks: 90
Thanked 1,620 Times in 1,509 Posts
isladogs is just really nice isladogs is just really nice isladogs is just really nice isladogs is just really nice isladogs is just really nice
Re: Set a group of controls as visible/hidden, enabled/disabled or locked/unlocked

Pleased it worked for you
BTW please see sticky post about reporting your own posts to moderated areas
__________________
If this answer has helped, please click the Thanks button and/or click the 'reputation scales' symbol on the left.

Web links:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Colin
Previously known as ridders : Access 2010 32-bit, Access 2016 32-bit & 64-bit, SQL Server Express 2014, Windows 10,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
isladogs is offline   Reply With Quote
Old 08-15-2018, 06:45 AM   #6
MajP
Newly Registered User
 
Join Date: May 2018
Posts: 479
Thanks: 6
Thanked 115 Times in 113 Posts
MajP will become famous soon enough
Re: Set a group of controls as visible/hidden, enabled/disabled or locked/unlocked

@Ridder
This is a good concept of using the TAG property to update multiple controls, but I think you have may lose the average user in some areas. Less may be more. I recommend get rid of this
Code:
Public Sub EnableControls(State As Boolean, Tg1 As String, Optional Tg2 As String, Optional Tg3 As String, _
        Optional Tg4 As String, Optional Tg5 As String, Optional Tg6 As String)

On Error GoTo Err_Handler

    'set controls to locked or not according to the control tag value
     For Each ctrl In Screen.ActiveForm.Controls
        Select Case ctrl.ControlType
        
        Case acLabel, acImage, acLine, acRectangle, acPageBreak
            'no code here - these can't be disabled
        Case Else
            If ctrl.Tag = Tg1 Or ctrl.Tag = Tg2 Or ctrl.Tag = Tg3 Or ctrl.Tag = Tg4 _
                    Or ctrl.Tag = Tg5 Or ctrl.Tag = Tg6 Then ctrl.Enabled = State
        End Select
        
    Next ctrl
  
Exit_Handler:
    Exit Sub

Err_Handler:
    MsgBox "Error " & Err.Number & " " & Err.description
    Resume Exit_Handler
    
End Sub
You make your code less generic (unless you get rid of those tag parameters and add a ParamArray). Recommend replace simply with the below code because the multiple tags does not add to what you are trying to demonstrate and only adds a level of complexity. I understand you are trying to be efficient, but does not really help show what you are doing.

Code:
Public Sub EnableControls(State As Boolean, TheTag as string)
On Error GoTo Err_Handler
    'set controls to Enabled or not according to the control tag value
     For Each ctrl In Screen.ActiveForm.Controls
        If ctrl.Tag = TheTag Then ctrl.Enabled = State
    Next ctrl
 
Exit_Handler:
    Exit Sub

Err_Handler:
    MsgBox "Error " & Err.Number & " " & Err.description
    Resume Exit_Handler
    
End Sub
Then modify the call from
Code:
EnableControls True, "A", "B", "C", "D"
    ShowControls True, "A", "B", "C", "D"
    LockControls False, "A", "B", "C", "D"
to the longer but simpler for the average user to follow
Code:
    EnableControls True, "A" 
    EnableControls True, "B"
    EnableControls True, "C"
    EnableControls True, "D" 
    ShowControls True, "A"
    ....
    ShowControls True, "D"
    LockControls False, "A"
    ...
    LoctControls False, "D"
Also may want to label the controlType subform as for information only. I was lost on what its purpose was. I assumed you actually used it to determine if a control had the property, but you do not it is for visibility only. If you do then I recommend adding the field controltypevalue.
ControlTypeValue 'Long
Code:
ControlType	ControlTypeValue
acLabel         100
acRectangle     101
acCommandButton 104
acOptionButton  105
acCheckBox      106
acOptionGroup   107
acTextBox       109
acListBox       110
acComboBox      111
acTabCtl        123
....
Then if you made the field names the actual Property name and made the values boolean (Show/Hide to Visible, Enable/Disable to Enable, Lock/Unlock to Lock) you could actually check this table to see if a property is settable
Code:
Public Function HasProperty(PropName As String, ControlType As Long) As Boolean
  'This may be more work than it is worth. You would have to keep the table updated. You are probably better off just trapping the error if the property does not exist
  HasProperty = Nz(DLookup(PropName, "tblControlTypes", "ControlTypeValue = " & ControlType), False)
End Function
However, it may just be quicker to try to set a property that does not exist and throw the error.
MajP is offline   Reply With Quote
Old 08-16-2018, 11:10 PM   #7
isladogs
Part time moderator
 
isladogs's Avatar
 
Join Date: Jan 2017
Location: Somerset, UK
Posts: 6,615
Thanks: 90
Thanked 1,620 Times in 1,509 Posts
isladogs is just really nice isladogs is just really nice isladogs is just really nice isladogs is just really nice isladogs is just really nice
Re: Set a group of controls as visible/hidden, enabled/disabled or locked/unlocked

Hi MajP

Always happy to hear your opinion but in this case I completely disagree with it.

I tried it with a parameter array as suggested by static but user feedback from various forums was that the current system was preferred.

Similarly, feedback from users was that more concise code like
Code:
EnableControls True, "A", "B", "C", "D"
was preferable to writing each on a separate line.

But as both will work, users can decide for themselves

The subform is indeed for info / display purposes only.
The form includes examples of all standard control types.
I needed a subform so that worked on two levels.
If users needed it in their own databases, I would have told them to include it

As for your final point, I dislike code that is designed around checking for a property error.
Sometimes it is unavoidable however.


__________________
If this answer has helped, please click the Thanks button and/or click the 'reputation scales' symbol on the left.

Web links:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Colin
Previously known as ridders : Access 2010 32-bit, Access 2016 32-bit & 64-bit, SQL Server Express 2014, Windows 10,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Last edited by isladogs; 08-17-2018 at 03:26 AM.
isladogs is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Setting a group of controls visible/hidden or enabled/disabled isladogs Modules & VBA 9 04-27-2017 05:59 AM
Click Locked/Disabled controls, prompt for variable Futures_Bright Modules & VBA 0 08-06-2013 02:44 AM
Make Controls visible with Option group IanT76 Forms 4 07-09-2012 10:20 PM
Locked/unlocked aldeb Forms 1 06-13-2005 08:15 AM
locked and unlocked records Webster01 Forms 1 03-26-2002 08:25 AM




All times are GMT -8. The time now is 08:07 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Sponsored Links

How to advertise

Media Kit


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World