-
1
- #1
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 "Enabled"
End If
For Each ctl In frm.Controls
'Check for specified ControlType
If ctl.Properties("ControlType"
= 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, "cmdButton"
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("FormName"
, 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("FormName"
("SubFormName"
.Form, acTextBox, 1)
or
Call ChangeControlProperty(Forms!FormName!SubFormName.Form, acTextBox, 1)
Good luck!
Aivars
Riga,
Latvia
alaganovskis@hotmail.com
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 "Enabled"
End If
For Each ctl In frm.Controls
'Check for specified ControlType
If ctl.Properties("ControlType"
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, "cmdButton"
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("FormName"
or
Call ChangeControlProperty(Forms!FormName, acCommandButton, 1)
6. Change Enabled property of all subform's textboxes of another form to opposite
Call ChangeControlProperty(Forms("FormName"
or
Call ChangeControlProperty(Forms!FormName!SubFormName.Form, acTextBox, 1)
Good luck!
Aivars
Riga,
Latvia
alaganovskis@hotmail.com