Registrations are now open. Join us today!
There is still a lot of work to do on the wiki yet! More information about editing can be found here.
Already have an account?

Microsoft KB Archive/173517

From BetaArchive Wiki
Knowledge Base


Article ID: 173517

Article Last Modified on 10/11/2006



APPLIES TO

  • Microsoft Access 2.0 Standard Edition



This article was previously published under Q173517

Moderate: Requires basic macro, coding, and interoperability skills.

SUMMARY

When you open a form in datasheet view in Microsoft Access version 2.0, and then make any modifications to the layout of the form, such as increasing the width of a column, Microsoft Access prompts you to save the changes to the form when you close it.

If you do not have design rights to the datasheet form, Microsoft Access cannot save the changes you made while viewing the form. When you try to save the form, you receive the following error message:

You don't have permissions to modify form '<name of form>'

MORE INFORMATION

To prevent Microsoft Access from prompting you to save the form, use one of the following methods. The first method involves embedding your datasheet form as a subform within an unbound main form. The second method uses application programming interface (API) function calls in an Access Basic procedure.

Method 1

  1. Create a new blank form and set the following properties:

       Form: frmTest
       ----------------------------
       Caption: <same as subform's>
       ControlSource: <none>
       Default View: Single Form
       Scroll Bars: Neither
       Record Selectors: No
       Navigation Buttons: No
                        
  2. Add your datasheet form as a subform to the new blank form.
  3. Resize and reposition the subform to remove all the unused space in the master form.
  4. Save the master form. When you open the master form, it looks like your datasheet form; however, changing the column size or font doesn't affect the datasheet form's design. Therefore, closing the master form doesn't prompt you to save any changes.

Method 2

Advanced: Requires expert coding, interoperability, and multi-user skills.

This method assumes that you are familiar with Access Basic and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Access Basic, please refer to the "Building Applications" manual.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. NOTE: In the following sample code, an underscore (_) at the end of a line is used as a line-continuation character. Remove the underscore from the end of the line when re-creating this code.

You may have some Microsoft Windows API functions defined in an existing Microsoft Access library; therefore, your declarations may be duplicates. If you receive a duplicate procedure name error message, remove or comment out the declarations statement in your code.

  1. Create a new form to prompt the user. This is necessary to prevent the existing datasheet form from calling the API function.

    Form: frmCloseDialog
          -----------------------------
          Name: frmCloseDialog
          Caption: Close Datasheet form
          Recordsource: <none>
          Default View: Single Form
          Views Allowed: Form
          Scroll Bars: Neither
          Record Selector: No
          Navigation Buttons: No
          Border Style: Dialog
    
          Label:
             Name: lblPrompt
             Caption: Are you sure you want to close the form?
          Command Button:
             Name: cmdCloseForm
             Caption: OK
             On Click: [Event Procedure]
          Command Button:
             Name: cmdCancel
             Caption: Cancel
             On Click: [Event Procedure]
                        
  2. On the View menu, click Code to display the form's module. Type the following lines of code within the form's module:

          Option Explicit
    
          Declare Function KillForm Lib "User" _
            Alias "DestroyWindow" (ByVal intWinHandle As Integer) As Integer
    
          Sub cmdCancel_Click ()
             On Error GoTo ErrCmdCancel
             DoCmd Close
    
          ExitCmdCancel:
             Exit Sub
    
          ErrCmdCancel:
             MsgBox Error$
             Resume ExitCmdCancel
          End Sub
    
          Sub cmdCloseForm_Click ()
             Dim intResult As Integer, intHnd As Integer
             On Error GoTo errCloseForm
    
             ' Set the focus back to the datasheet form prior to saving the
             ' record.
    
             Forms![frmDatasheet].SetFocus
             DoCmd DoMenuItem A_FORMBAR, A_FILE, A_SAVERECORD, ,A_MENU_VER20
    
             ' Grab the window handle of the datasheet form, and
             ' Invoke the DestroyWindow API call to close the datasheet form.
    
             intHnd = forms!frmDatasheet.hwnd
             intResult = KillForm(intHnd)
    
             ' Close the cancel dialog form frmCloseDialog.
             DoCmd Close A_FORM, Me.Name
          ExitCloseForm:
             Exit Sub
          ErrCloseForm:                 ' In case the datasheet form wasn't
                                        ' open.
             MsgBox Error$
             Resume ExitCloseForm
          End Sub
                        
  3. Close and save the form created in step 3 as frmCloseDialog.
  4. Open the datasheet form (frmDatasheet) in Design view and view its properties.
  5. Set the form's OnUnload property to the following event procedure:

          Sub Form_Unload (Cancel As Integer)
             ' Cancel the unload event of the Datasheet form, and open
             ' the dialog form created within Step 1.
    
             Cancel = True
             DoCmd OpenForm "frmCloseDialog"
          End Sub
                        
  6. Close and save the form.
  7. Open the datasheet form, and modify the width of the first column. Note that when you try to close the datasheet form, the dialog form prompts you to select either OK or Cancel. When you click OK, the datasheet form closes without prompting you to save the changes to the form.


REFERENCES

For more information about declaring Windows APIs, search the Help Index for "Declare external procedures."


Additional query words: inf

Keywords: kbhowto kbprogramming KB173517