Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function for change of Enabled, Locked, Visible properties to opposite 1

Status
Not open for further replies.

Aivars

Programmer
May 4, 2001
687
LV
Hi everybody!

I'm observed that this Tek-Tips forums' members often ask how to change Enabled, Locked, Visible properties of all spec type form's controls.
Here is function which would be helped to solve some few of its.

'***************************************
Public Sub ChangeControlProperty(frm As Form, _
intCtlType As Integer, _
Optional btyProp As Byte = 1, _
Optional strExcludeCtlName As String = "")
'Function for change of all specified form's controls
'Enabled, Locked, Visible properties to opposite
'
'2000, Mai 10

'-------------------------------------------
'Constants of Control types:
'acBoundObjectFrame - Bound object frame
'acCheckBox - Check box
'acComboBox - Combo box
'acCommandButton - Command button
'acCustomControl - ActiveX (custom) control
'acImage - Image
'acLabel - Label
'acLine - Line
'acListBox - List box
'acObjectFrame - Unbound object frame or chart
'acOptionButton - Option button
'acOptionGroup - Option group
'acPage - Page
'acPageBreak - Page break
'acRectangle - Rectangle
'acSubform - SubForm / SubReport
'acTabCtl - Tab
'acTextBox Text box
'acToggleButton - Toggle button

'-------------------------------------------

Dim ctl As Control

On Error Resume Next
If btyProp < 1 Or btyProp > 3 Then
btyProp = 1
'Select Property &quot;Enabled&quot;
End If

For Each ctl In frm.Controls
'Check for specified ControlType
If ctl.Properties(&quot;ControlType&quot;) = intCtlType Then
If ctl.Name <> strExcludeCtlName Then
'Change property (exclude specified control)
Select Case btyProp
Case 1
ctl.Enabled = Not ctl.Enabled
Case 2
ctl.Locked = Not ctl.Locked
Case 3
ctl.Visible = Not ctl.Visible
End Select
End If
End If
Next

End Sub

'***************************************

Copy function above into any module then try to call it from your forms codes.

Examples of using:
1. Change Enabled property of all active form's commandbuttons to opposite exclude itself
Private Sub cmdButton_OnClick()
Call ChangeControlProperty(Me, acCommandButton, 1, &quot;cmdButton&quot;)
End Sub


2. Change Locked property of all active form's textboxes to opposite
Call ChangeControlProperty(Me, acTextBox, 2)

3. Change Visible property of all active form's labels to opposite
Call ChangeControlProperty(Me, acLabel, 3)

4. Change Enabled property of all subform's textboxes to opposite
Call ChangeControlProperty(Me.subFormName.Form, acTextBox, 1)

5. Change Enabled property of all another form's commandbuttons to opposite
Call ChangeControlProperty(Forms(&quot;FormName&quot;), acCommandButton, 1)
or
Call ChangeControlProperty(Forms!FormName, acCommandButton, 1)

6. Change Enabled property of all subform's textboxes of another form to opposite
Call ChangeControlProperty(Forms(&quot;FormName&quot;)(&quot;SubFormName&quot;).Form, acTextBox, 1)
or
Call ChangeControlProperty(Forms!FormName!SubFormName.Form, acTextBox, 1)

Good luck!
Aivars :p
Riga,
Latvia
alaganovskis@hotmail.com
 

Aivars,

Great TIP. Will you publish it a a FAQ? Tips disappear from view very quickly in this forum. Terry L. Broadbent
faq183-874 contains some tips and ideas for posting questions in these forums. Please review it and comment if you have time.
NOTE: Reference to the FAQ is part of my signature and is not directed at any individual.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top