Hi all,
Could you please give me some suggestions about Form closing? My problem is that I will do the checking before closing the main Form whether the user saves the data, but I really don't know how to solve it.
If the user doesn't save the data and close the Form, it will show a message and the main Form should be still there. That will not be closed.
I will show you my sample code.

Dim bStop As Boolean

Private Sub Command1_Click()
bStop = True
End Sub

Private Sub Form_Unload(Cancel As Integer)
If bStop = False Then
MsgBox "Don't close the Form and save the data first."
Exit Sub
Else
MsgBox "Close the Form"
End If
End Sub

Pls give me a hand.

Thanks,
zawpai

try this code, message will show when you click on x button.

Private Sub Form_Unload(Cancel As Integer)
If MsgBox("Are u sure want to quit?", 4 + 32, "Exit Confirm") = 7 Then
    Cancel = True
Else
    End
End If
End Sub

On the save button put a boolean..

sub cmdSave_Click()
ifSave = true
end sub

then check when the user attempts to close the form...

Private Sub Form_Unload(Cancel As Integer)
if ifSave=true then
end
else
'put Jx code here
end if
End Sub

Hi all,

Now, I have already solved my problem. I doesn't use database to save the data. I just save them as a text file.

Thanking for giving me a hand.

Best Regards,
zawpai

This article has been dead for over six months. Start a new discussion instead.