Microsoft KB Archive/101308

{|
 * width="100%"|

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

 * }

Q101308

-

The information in this article applies to:


 * Microsoft Access versions 1.0, 1.1

-

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:

  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   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   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.  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. 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.</li> 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.</li></ol>