Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form exiting, please help

Status
Not open for further replies.
Jul 19, 2003
19
IN
how we write command to exit form with Button "Cancel"
 
This is the common code I use to call it from anywhere
Code:
Public Sub cmdExit_Click()
On Error GoTo Err_cmdExit_Click
 Dim intResponse As Integer
    Dim strPrompt As String
    strPrompt = "Are you sure you want to Quit the Database?"
    intResponse = MsgBox(strPrompt, vbQuestion + vbYesNo, "MyDBName")
    If intResponse = vbYes Then   
         DoCmd.Quit
    Else
Exit_cmdExit_Click:
    Exit Sub
Err_cmdExit_Click:
    MsgBox Err.Description
    Resume Exit_cmdExit_Click
 End If
End Sub
or simply
Code:
Private Sub cmdExit_Click()
On Error GoTo Err_cmdExit_Click
   If MsgBox("Are you sure you want to Quit the Database?", vbQuestion + vbYesNo, "MyDBName") = vbYes then   
         DoCmd.Quit
    Else
Exit_cmdExit_Click:
    Exit Sub
Err_cmdExit_Click:
    MsgBox Err.Description
    Resume Exit_cmdExit_Click
 End If
End Sub


Zameer Abdulla
Visit Me
 
I think you want to close a form not to quit the DB then pls change purple text
Code:
Private Sub cmdExit_Click()
On Error GoTo Err_cmdExit_Click
   If MsgBox("Are you sure you want to Close the form?", vbQuestion + vbYesNo, "MyDBName") = vbYes then   
   [purple][b]DoCmd.Close acForm, "MyFormName"
[/b][/purple]    Else
Exit_cmdExit_Click:
    Exit Sub
Err_cmdExit_Click:
    MsgBox Err.Description
    Resume Exit_cmdExit_Click
 End If
End Sub


Zameer Abdulla
Visit Me
 
I am sorry I was thinking I am in MS Acces Form Forum
But the concept is same
only to change
Code:
Private Sub cmdExit_Click()
On Error GoTo Err_cmdExit_Click
   If MsgBox("Are you sure you want to Close the form?", vbQuestion + vbYesNo, "MyDBName") = vbYes then   
   [purple][b]Me.Hide[/b][/purple]
    Else
Exit_cmdExit_Click:
    Exit Sub
Err_cmdExit_Click:
    MsgBox Err.Description
    Resume Exit_cmdExit_Click
 End If
End Sub
or
Code:
Unload Me

Zameer Abdulla
Visit Me
 
unload <form>
is working

your fist code is giving message "Object required"

anyway
Thank You

__King__
 
[purple]DoCmd.Close acForm, "MyFormName"[/purple] is MS Access command to close a form can't be used in VB6. You will get an [purple]Object Required[/purple] message
[purple]
Unload FormName[/purple] is VB that can be used as public.

[purple]Me.Hide[/purple] is VB but can be used only as private.


Zameer Abdulla
Visit Me
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top