Microsoft KB Archive/93298

{|
 * width="100%"|

ACC1x: How to Use Visible Property to Simulate Property Changes

 * }

Q93298

-

The information in this article applies to:


 * Microsoft Access versions 1.0, 1.1

-

SUMMARY
Microsoft Access does not allow you to change some control properties, such as Color and Caption, at run time. This article discusses how you can work around this limitation.

MORE INFORMATION
You can work around this limitation by creating two controls that are identical except for the property you want to change. You place these controls at the same location with their Visible property set to No. At the point where the property is to change, set the Visible property of the control with the desired property setting to Yes using a Macro SetValue action, and set the Visible property of the other control to No in the same manner.

The following example demonstrates this method. In the example, a form appears with one button and text box. The text box is Blue, and the button has the Caption &quot;Red.&quot; When you click the button, the text box's color will change to red and the button's caption will change to &quot;Blue.&quot; Clicking the Blue button will toggle back to Red, and so on.

  Create a new form with the following two text boxes:

     Text Box -     Control Name: Red Fill Color: 255 Visible: No

Text Box Control Name: Blue Fill Color: 16711680 Visible: Yes  Position the text box called Blue directly on top of the text box called Red and make sure they are exactly the same size so that one covers the other.  Add the following two command buttons to the form:

     Command Button Control Name: RedButton Caption: Change to Red Visible: Yes On Push: ChangeColor.Red

Command Button -     Control Name: BlueButton Caption: Change to Blue Visible: No     On Push: ChangeColor.Blue  Position the command button called BlueButton directly on top of the command button called RedButton and make sure they are exactly the same size so that one covers the other.  Add the following text box to the form and delete its label:

     Text Box -     Control Name: GiveMeFocus Width: 0

The purpose of the zero width for the text box is to maintain focus while the Visible properties of other controls are changing.  Save the form as ChangeColor and then close it.  Create the following new macro:

<pre class="FIXEDTEXT">     Macro Name  Action          Arguments ---     Blue        GoToControl     ControlName .. GiveMeFocus SetValue       Item ......... [Blue] Expression ... [Red] SetValue       Item ......... [Blue].Visible Expression ... True SetValue       Item ......... [Red].Visible Expression ... False SetValue       Item ......... [RedButton].Visible Expression ... True SetValue       Item ......... [BlueButton].Visible Expression ... False Red        GoToControl     ControlName .. GiveMeFocus SetValue       Item ......... [Red] Expression ... [Blue] SetValue       Item ......... [Red].Visible Expression ... True SetValue       Item ......... [Blue].Visible Expression ... False SetValue       Item ......... [BlueButton].Visible Expression ... True SetValue       Item ......... [RedButton].Visible Expression ... False </li> Save the macro as ChangeColor and then close it.</li> Open the ChangeColor form in Form view. Type any text in the text box, and then click the command button. Note that each time you click the command button, the color and caption of the button changes, without changing the value of the text box.</li></ol>