Hi

I just wonder how to enabled the X in the right
upper corner of a form.
When I press the X then I will that it goes to cmdquit
and the program is ending.

How to do that

Lennie

I just wonder how to enabled the X in the right
upper corner of a form.

What you mean about x mark in the right upper corner? Are you put a button or some other control there?

When I press the X then I will that it goes to cmdquit
and the program is ending.

I don't know why you need make it goes to cmdquit again since you can close your program when you click on X mark (button or any other controls). Like this following code :

Private Sub btnX_Click()
    End
End Sub

But if you want to make it call cmdquit then here is the way.
I assume the x mark as button (but you can use another controls).
Also i don't know what it's in cmdquit but you said about ending the program.

Private Sub cmdquit_Click()
    End
End Sub

Private Sub btnX_Click()
    ' This line of code will call 
    Call cmdquit_Click
End Sub

Or you mean about close button (X) on form title bar?
If yes then you can use form unload event :

Private Sub Form_Unload(Cancel As Integer)
    Call cmdquit_Click
End Sub

Edited 3 Years Ago by Jx_Man

Attachments X_marks.jpg 25.72 KB

JX
it won't work as I will
Ok it close all but I will
it shall go to cmdquit where
a msgbox is and I can choose
vbyes or vbno
If vbyes=true
then it makes backup of some files
and vbno end the sub

JX
it won't work as I will
Ok it close all but I will
it shall go to cmdquit where
a msgbox is and I can choose
vbyes or vbno
If vbyes=true
then it makes backup of some files
and vbno end the sub

I'm suggesting you to put the backup code in procedure or function. You can call it when you needed, which it in cmdquit button or when you pressing X button.

Try this following codes. Modified as you needed :

Private Sub BackUpDB()
    ' Backup codes here
    MsgBox "backup success"
End Sub

Private Sub cmdquit_Click()
    ' Your cmdquit code here
    ' Call BackUpDB after your vbYes line code.
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Dim state As Integer

    state = MsgBox("Are you realy want to exit this program? ", vbYesNo, "Exit?")
    If state = vbYes Then
        BackUpDB 'call backupdb procedure here
    Else
        Cancel = True ' just cancel exit
    End If
End Sub

Hope it solve your problem.

This question has already been answered. Start a new discussion instead.