close error (1 Viewer)

zoona

New member
Local time
Today, 02:26
Joined
Oct 25, 2014
Messages
3
Hi all I am new to access VB

I the code below to close 'frm_two'

but all I get is a run time error



Private Sub Command0_Click()


On Error GoTo HandleError
DoCmd.RunCommand acCmdSaveRecord
DoCmd.Close acForm, Form_frm_two, acSavePrompt

HandleExit:
Exit Sub
HandleError:
MsgBox Err.Description
Resume HandleExit

End Sub

Private Sub Form_Unload(Cancel As Integer)

If AllowClose = False Then
Cancel = True
MsgBox "Use the Form -> Close option to close this form"
Me.Visible = True
End If

End Sub
 

MarkK

bit cruncher
Local time
Yesterday, 18:26
Joined
Mar 17, 2004
Messages
8,181
Hi. What error do you get? What line causes the error?
 

moke123

AWF VIP
Local time
Yesterday, 21:26
Joined
Jan 11, 2013
Messages
3,915
i think the close event occurs before the unload event so if your trying to cancel the close event its too late.

if your trying to force the user to use the close command button rather than the "X", just disable the "X" by setting the close button to no in the form properties.
 

missinglinq

AWF VIP
Local time
Yesterday, 21:26
Joined
Jun 20, 2003
Messages
6,423
DoCmd.Close acForm, Form_frm_two, acSavePrompt

needs to be

DoCmd.Close acForm, "frm_two", acSavePrompt

Linq ;0)>
 

Users who are viewing this thread

Top Bottom