Set same properties for several controls

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have many controls on a form. Depending on conditions, I wish to change
the properties on various controls i.e. visible, background colour, etc. How
can I do this? Thanks.
 
I have many 12 boxes containing values relating to actual and forecast
amounts, for cost centers and accounts. Depending on the period, the amounts
these text boxes contain can represent either actual or forecast information.
I wish to lock and change the background colour of the actual text boxes
differently than that forecast text boxes. Im not sure how to do this with
conditionaly formatting. I think i need a means to name the controls and
change them enmasse. What is the best way to do this?

Kevin
 
Conditional formatting allows you to format a control based on it's value,
or on the value of another field. If you tell us what you want
(specifically) for a field or two, I can tell you how to set it up. I'd
need to know the name of your field and what would determine it's format.

Rick b
 
The data in this example is based on a table and is represented by the
following textboxes in multiple subforms i.e.: txtJan, txtFeb, txtMar, etc.
The values themselves contain no logic that associates themselves to 'actual'
or 'forecast'. The record has no indicator that helps me determine its
association. The only indicator resides in another table. I can do a
dlookup to return this information, but still have the problem of assigning
property changes to large numbers of fields (12 months x18 subforms=216
fields).

Kevin
 
I'm not sure this is of any help but here's a function that returns the
average of certain controls on a form based upon the name of the control.
You might be able to use this to write a function that changes the property
of many textboxes on a form:

Public Function AveAllControlsOnFormWithFieldName(strFieldName As String) As
Double
' this function returns the Average of all controls on the form
' that have strFieldName as part of their name

Dim dblControlSum As Double, strControlName As String,
lngNumOfNumericControls As Long
Dim NumOfControls As Long, I As Long, lngControlCount As Long

NumOfControls = Me.Controls.Count ' number of controls on form
dblControlSum = 0 ' stores the sum
lngNumOfNumericControls = 0 ' keeps track of how many numeric controls
' now loop through every control on form
For I = 0 To (NumOfControls - 1) ' controls start at 0
If IsNumeric(Me(I)) Then ' check to see if it's a number
strControlName = Me(I).Name ' store the name of the control
' now see if the second string is contained in the first
If InStr(1, strControlName, strFieldName, vbTextCompare) > 0
Then
dblControlSum = dblControlSum + Me(I).Value ' if substring
is found then
lngNumOfNumericControls = lngNumOfNumericControls + 1
End If
End If
Next I
AveAllControlsOnFormWithFieldName = dblControlSum /
lngNumOfNumericControls
End Function
 
Back
Top