Anyone,
I am trying to create a public function that loops through all of the
controls on an open form and makes certain corrections. Currently I have this
code written in every form, and believe there is a better way. If anyone has
any ideas, I am open to your insight and discussion insights.
Thanks,
Merrick
Code Sample:
Public Sub Reset_Form_Controls(ByRef frm As Form)
'
*****************************************************************************************
' Author: Merrick S. Watchorn
' Version: 2009/04/13
' Purpose: Reformats all controls.
'
*****************************************************************************************
' Module Change Log Entries
'
*****************************************************************************************
' Date Description
Author
' 20090413 Write the original code to execute the purpose statement.
MSW
'
*****************************************************************************************
Dim ctl As Control
'
*****************************************************************************************
On Error GoTo errHandler
'
*************************************************************************************
For Each ctl In frm.Controls
' Make the required changes.
With ctl
' Use the select case option to look for control types.
Select Case .ControlType
Case acTextBox
' Make the required changes.
.SpecialEffect = 2
.BorderStyle = 1
.BorderWidth = 3
Case acComboBox
' Make the required changes.
.SpecialEffect = 2
.BorderStyle = 1
.BorderWidth = 3
Case acListBox
' Make the required changes.
.SpecialEffect = 2
.BorderStyle = 1
.BorderWidth = 3
End Select
End With
Next ctl
Sub_Exit:
'
*****************************************************************************************
Set ctl = Nothing
Exit Sub
errHandler:
'
*****************************************************************************************
MsgBox ("Error No: " & Err.Number & ", " & Err.Description), vbCritical,
strDB_Title
'
*****************************************************************************************
End Sub