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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code to prevent Access from closing by using the "X" button 2

Status
Not open for further replies.

DBSSP

Programmer
Apr 1, 2002
327
US
I'm having a slight issue with the database I'm working on. I have two forms in question, one for entry to the database, and one for when they finish for the day. Each one logs time in and time out, along with the dat and their name. Problem is that the last form pulls data from the first form, and then saves all information as one record. If the user closes access by clicking the close button ("X") then the form doesn't save the data because, the user hasn't even opened it. Is there a better way to log time, or some way to force the user to close via the menu and this form?

Jay [infinity]
"If the words up and down were reversed, would you trip and fall or trip and fly?"
 
You can create a command button to set a variable and close the form. Use the Unload event of the form to check the variable and if it hhasn't been set properly, Cancel = True.

User can only Ctrl+Alt+Del to quit Access otherwise than through the command button...

Good luck



[pipe]
Daniel Vlas
Systems Consultant

 
I can't get it to work correctly, do you have an example or perhaps could you pseudo code it for me. It's been awhile since I've had to go through VBA.

Jay [infinity]
"If the words up and down were reversed, would you trip and fall or trip and fly?"
 
In the declarations section of form's module:
Dim varAllowQuit As Boolean

Create a command button (butQuit) with the following code:

Private Sub butQuit_Click()
varAllowQuit = True
DoCmd.Close
'or
'DoCmd.Quit
End Sub

Then, the Unload event:

Private Sub Form_Unload(Cancel As Integer)
If varAllowQuit Then Exit Sub
Cancel = True
MsgBox "Dude, click the button!"
End Sub


That should be all...

Good luck


[pipe]
Daniel Vlas
Systems Consultant

 
Hello,

use this in the form that should be not closed by X

Code:
Private Sub Form_Unload(Cancel As Integer)
    Cancel = True
End Sub

Note that it would be better to use a global variable (default set TRUE).
If the user should be able to terminate nevertheless, then you only have to set the variable = FALSE and the form closes as usual.

Regards
Daniel
 
Daniel (what a coincidence)!

How in the world are you going to close the form in the end? Your line works, but will drive the user crazy....There is no way of closing the application.

Please read above.



[pipe]
Daniel Vlas
Systems Consultant

 
Thank you very much! It works! I only have one minor bug to work out and that's to keep the popup from displaying when the user clicks the Exit button on the second form.

I placed the code into the switchboard where the illegal-closing is typically happening. So the user clicks exit on the switchboard, and the final confirmation form pops up asking them to verify some info for their session. Then they click the exit button on this form and it closes the entire application. But that popup is kinda getting in the way, although the application still closes.

Jay [infinity]
"If the words up and down were reversed, would you trip and fall or trip and fly?"
 
Hi Daniel,

you'r right. Sorry for my terrible english ... what you mean is the same as I. If you have an normal exit-button on your form you can set the global var ("bol_allowExit" or any other) to false in the Exit_onclick . The unload event have to be changed to

Private Sub Form_Unload(Cancel As Integer)
    Cancel = bol_allowExit
End Sub

ok?!

Daniel
 
Thanks alot, both of you! Stars all around!

Jay [infinity]
"If the words up and down were reversed, would you trip and fall or trip and fly?"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top