Menutup Form = Menutup Access

9 May

To: belajar-access@yahoogroups.com
From: “Sofyan Efendi”
Date: Wed, 6 Sep 2006 11:29:41 +0700

PERTANYAAN:

Bagaimana cara nya supaya tombol close yg ada di Form jika di klik maka akan menutup form tsb, sekaligus menutup Program MS. Access nya ?
Tombol Close nya di bikin dari Command Button -> Form Operation -> Close Form, yang kalo di liat dari jendela VBA nya sbb :
———— ——— ——— ——— ——— ——— –
Private Sub cmd_Exit_Click( )
On Error GoTo Err_cmd_Exit_ Click
If MsgBox(“Yakin Mau keluar dari Program ini ?”, vbQuestion +
vbYesNo, “Exit”) = vbYes Then
DoCmd.Close
End If
Exit_cmd_Exit_ Click:
Exit Sub
Err_cmd_Exit_ Click:
MsgBox Err.Description
Resume Exit_cmd_Exit_ Click
End Sub
———— ——— ——— ——— ——— ——— –
Terima kasih
Sarwan

JAWABAN:

Ubah perintah DoCmd.Close menjadi DoCmd.Quit. Sehingga procedurenya menjadi:

———— ——— ——— ——— ——— ——— –
Private Sub cmd_Exit_Click( )
On Error GoTo Err_cmd_Exit_ Click
If MsgBox(“Yakin Mau keluar dari Program ini ?”, vbQuestion +
vbYesNo, “Exit”) = vbYes Then
DoCmd.Quit
End If
Exit_cmd_Exit_ Click:
Exit Sub
Err_cmd_Exit_ Click:
MsgBox Err.Description
Resume Exit_cmd_Exit_ Click
End Sub
———— ——— ——— ——— ——— ——— –

Namun procedure diatas tidak efektif, karena jika user meng-klik tanda silang (close) langsung pada jendela Access (yang paling atas dan paling kanan), maka perintah diatas tidak akan dijalankan. Lalu bagaimanakah mengatasi hal ini?

Jangan menggunakan command button, namun manfaatkanlah event Unload pada form.

Private Sub Form_Unload( Cancel As Integer)
On Error GoTo Nol
Dim tanya As Long
tanya = MsgBox(“Anda hendak keluar program ?”, vbYesNo + vbDefaultButton2 + vbQuestion)
If tanya = vbYes Then
DoCmd.Quit
Else
Cancel = -1
End If
Nol:
End Sub

Wassalaamu’alaikum Warahmatullahi Wabarakatuh,
Sofyan Efendi
– AccessWeb
– OPI-Homepage

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: