ACC2: How to Close Datasheet Form Without Saving Design ChangesID: Q173517
|
Moderate: Requires basic macro, coding, and interoperability skills.
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>'
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.
Form: frmTest
----------------------------
Caption: <same as subform's>
ControlSource: <none>
Default View: Single Form
Scroll Bars: Neither
Record Selectors: No
Navigation Buttons: No
http://www.microsoft.com/mcsp/For more information about the support options available from Microsoft, please see the following page on the World Wide Web:
http://www.microsoft.com/support/supportnet/overview/overview.aspNOTE: 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.
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]
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
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
For more information about declaring Windows APIs, search the Help Index for "Declare external procedures."
Additional query words: inf
Keywords : FmrHowto
Version : WINDOWS:2.0
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: July 6, 1999