ACC1x: How to Use Visible Property to Simulate Property Changes

ID: Q93298


The information in this article applies to:


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 "Red." When you click the button, the text box's color will change to red and the button's caption will change to "Blue." Clicking the Blue button will toggle back to Red, and so on.

  1. 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 


  2. 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.


  3. 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 


  4. 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.


  5. 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.


  6. Save the form as ChangeColor and then close it.


  7. Create the following new macro:
    
          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 


  8. Save the macro as ChangeColor and then close it.


  9. 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.



REFERENCES

For more information about changing form properties at run time, please see the following article in the Microsoft Knowledge Base:

Q101308 ACC1x: How to Switch Form to Design Mode to Change Properties

Additional query words: runtime read only


Keywords          : kbusage FmsProp 
Version           : 1.0 1.1
Platform          : WINDOWS 
Issue type        : kbhowto 

Last Reviewed: March 12, 1999