green coder
green coder

Reputation: 55

MS Access database close, ignore form close cancel true

I created a MS Access database with multiple forms. One of the form is a switchboard that leads to other forms. I wanted to make sure that the switchboard form never closes. So in the switchboard form I did:

Private Sub Form_Unload(Cancel As Integer)
    Cancel = True
    MsgBox "You cannot close the switchboard"
End Sub

However, I realized that when a user wants to exit the database using the close database at the top it triggers the message box above. I understand why this happens as Access probable tries to close all of the open window before closing the database.

Is there a way to change my vba to understand that the form close is coming from database close event. Or is there any better way to prevent form close?

Upvotes: 0

Views: 663

Answers (1)

Krish
Krish

Reputation: 5917

There are several way and everyone preferes different way of achieving this. As for being user-friendly, if the user wants to close the database they should be able to. So instead of saying you cannot, why don't you just ask Would you like to close? if yes allow them to close.

2> If you really want to prevent them closing the form, why don't you remove all close buttons, borderStyle=none, closebuttons =false maybe poup = true?

Upvotes: 1

Related Questions