Garcimat
Member
- Local time
- Tomorrow, 07:58
- Joined
- Jun 7, 2022
- Messages
- 67
Hi guys
I am trying to not allow users to close the application using the Access X button.
I have an public variable called fcanIclose as Boolean
here is the code:
Private Sub Form_Unload(Cancel As Integer)
If fcanIclose = False Then
Cancel = True
MsgBox "You cannot close using tis button.You may exit the system from the main greeting screen", , "My Application"
End If
End Sub
up to here works fine would not close the Access, then I need a Close button on my form, code below:
…………….
Private Sub btn_Exit_Click()
On Error GoTo Err_quit
If MsgBox("Are you sure you wish to close the application ?", vbYesNo, "My Application") = vbYes Then
fcanIclose = False
DoCmd.Quit
End If
Exit_Quit:
Exit Sub
Err_quit:
MsgBox Err.Number & " " & Err.Description
Resume Exit_Quit
End Sub
The problem here is; when I click the form close button it give me the message:
"Are you sure you wish to close the application ?"
Answer = yes
That was supposed to close the access but does not close, instead give me the message from the form unload event
"You cannot close using tis button.You may exit the system from the main greeting screen"
Then when click ok the access is closed
I can’t understand why…..
thanks in advance
I am trying to not allow users to close the application using the Access X button.
I have an public variable called fcanIclose as Boolean
here is the code:
Private Sub Form_Unload(Cancel As Integer)
If fcanIclose = False Then
Cancel = True
MsgBox "You cannot close using tis button.You may exit the system from the main greeting screen", , "My Application"
End If
End Sub
up to here works fine would not close the Access, then I need a Close button on my form, code below:
…………….
Private Sub btn_Exit_Click()
On Error GoTo Err_quit
If MsgBox("Are you sure you wish to close the application ?", vbYesNo, "My Application") = vbYes Then
fcanIclose = False
DoCmd.Quit
End If
Exit_Quit:
Exit Sub
Err_quit:
MsgBox Err.Number & " " & Err.Description
Resume Exit_Quit
End Sub
The problem here is; when I click the form close button it give me the message:
"Are you sure you wish to close the application ?"
Answer = yes
That was supposed to close the access but does not close, instead give me the message from the form unload event
"You cannot close using tis button.You may exit the system from the main greeting screen"
Then when click ok the access is closed
I can’t understand why…..
thanks in advance