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

ID: Q101308


The information in this article applies to:


SUMMARY

There are a number of form properties in Microsoft Access that cannot be changed while the form is active. To work around this limitation, you can use a macro to change the form into Design view, use SetValue actions to change any property, and then change the form back to Datasheet view.


MORE INFORMATION

You can change the form into Design view by using a DoMenuItem macro action as shown below:


   MacroName   Action
   ----------------------
   Test1       DoMenuItem


   Test1 Actions
   -----------------------
   DoMenuItem

      Menu Bar: Form
      Menu Name: View
      Command: Form Design 

When you use this method to change properties on a Microsoft Access form, the following potential problems should be noted.

Problem 1

When changing from Datasheet view to Design view, or from Design view to Datasheet view, the form is in Design view yet repainting takes place on the screen. To minimize this problem, set Echo Off before going into Design view. Turn Echo On after forcing the form back into Datasheet view. The following sample illustrates this method:

   MacroName   Action
   ----------------------
   Test1       DoMenuItem

               Echo

   Test2       DoMenuItem

               Echo

   Test1 Actions
   -----------------------
   DoMenuItem

      Menu Bar: Form
      Menu Name: View
      Command: Form Design

   Echo

      Echo On: No

   Test2 Actions
   ------------------
   DoMenuItem

      Menu Bar: Form
      Menu Name: View
      Command: Browse

   Echo

      Echo On: Yes 

Problem 2

After a property is changed, the Save Form dialog box appears. To avoid this dialog box, set SetWarnings to Off from the form's OnClose event. If this is done in a macro, SetWarnings will automatically be reenabled after the form has been closed. The following sample demonstrates this method:
  1. Create a new form called "Form1" bound to the Categories table in the sample database NWIND.MDB with the following settings:
    
          Form
          --------------------------------
          Form: Form1
             Caption:  Form1
             ControlSource: Categories
             OnClose: Macro1.Onclose
          Textbox:  text box1
             ControlName:  Category ID
             ControlSource:  Category ID
          Textbox:  text box2
             ControlName:  Category Name
             ControlSource:  Category Name
          command button:  Button1
             Caption:  Filter
             OnPush:  =ChangeFilter()
          command button:  Button2
             Caption:  Close
             OnPush:  =Macro1.Close 


  2. Create a macro called "Macro1" with the following options:
    
          MacroName     Action          Defined Below
          -------------------------------------------
          OnClose       SetWarnings        1
          Close         Close              2
    
    
          1. OnClose Action
          -------------------
             Warnings On:  No
    
          2. Close Action
          ----------------------
             Object Type:  Form
             Object Name:  Form1 


  3. Add the following function to a new module:


    
          Function ChangeFilter ()
             DoCmd Echo False
             DoCmd DoMenuItem 0, 2, 0, 0
             Forms!Form1.AllowFilters = Not Forms!Form1.AllowFilters
             DoCmd DoMenuItem 0, 2, 1, 0
             DoCmd Echo True
          End Function 


    
       NOTE: For development work, you may want to comment out the DoCmd
       Echo actions. 


  4. Close and save the form, macro, and module.

    NOTE: Before closing the form, make sure that the Field List window, the property sheet, and the toolbox are closed.


  5. Open the form and choose Filter. Note that the filter buttons in the toolbar are unavailable. If you choose Filter again, the filter buttons in the toolbar become available.


  6. Close the form by choosing Close, or by double-clicking the form's Control-menu box. Note that regardless of which way the form is closed, no Save Form dialog box appears.



REFERENCES

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

Q93298 ACC1x: How to Use Visible Property to Simulate Property Changes

Additional query words: flip switch browse mode runtime run time read only


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

Last Reviewed: May 19, 1999