Article ID: 173517
Article Last Modified on 10/11/2006
Form: frmTest ---------------------------- Caption: <same as subform's> ControlSource: <none> Default View: Single Form Scroll Bars: Neither Record Selectors: No Navigation Buttons: No
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
Additional query words: inf
Keywords: kbhowto kbprogramming KB173517