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

Way To Pause Access From Closing?

Status
Not open for further replies.

Hakala

Technical User
Apr 26, 2006
144
US
Hi, Tek-Tips!

I'm getting a Run-time error 91 on closing my Access database, and when I choose "Debug," the screen goes to Visual Basic, but then the Close command takes over and Access closes, taking the VB window with it.

I can't see where my error is.

Is there a way to pause Access in the middle of the DoCmd.Quit command? Or is there some other way to tell Access to close which will allow me to stop it so I can get to the Debug screen?

I've even tried to screen print at exactly the right moment, but my system's too quick. :)

Thanks!
 
What about setting a line break in the code, early in the particular even that is triggering the close, and just step through the code after that point (F8).

To put a line-break in the code, go to the VBA screen, and look at the event you are needing to review, and where it says "Private Sub", left click over to the left of it, almost off that part of the screen, and it will highlight that line in a reddish color, and put a dot at the beginning of the line, signifying the code is to "break" or pause there, so that you can step through it. Maybe that will help get a better idea on your error.
 
Thank you, kjv1611. I've tried that, but since it's the Quit command that's the event, the screen doesn't stay up. It jumps to the code and I can see the break, but then Access closes and the Visual Basic window goes away.
 
Have you thought about putting a conditinoal statement in your code for this point of time.

Also, I thought that Quiting wasn't an event, but more a function you call within an event:

Code:
Private Sub Exit_Click()
  DoCmd.Quit
End Sub

Or is this something else?

If it is what I listed there, then maybe you can try:

Code:
Private Sub Exit_Click()
  If MsgBox ("Are you Sure", vbYesNo, "Exit?") = vbYes Then
    DoCmd.Quit
  End If
End Sub

Or else, maybe you could take another route, assuming the code is closing from a form:

Code:
Form_Unload
  'Put some code here (or if already have some, just put a line-break here)

End Sub
 
Haven't tested this because I'm at a computer without Access. However, have you tried including some error handling? Something like.

Private Sub Exit_Click()
On Error Go To QuitError
DoCmd.Quit
QuitError:
Stop
End Sub



Randy
 
That sounds like a great idea, Randy! Duh on my part! [blush]
 
Great ideas, but the Visual Basic screen won't stay open. I've tried both the error trap and the If/Then statement. The runtime error seems to occur during the Quit process.

Thank you for your help with this!
 
It's got to be something to do with a form unloading or something, I would think. Have you tried just closing the form via code as a test, instead of quitting the application, and see if you can pause it there - you should be able to do this:

Code:
Private Sub Exit_Click()
  [green]'DoCmd.Quit
  DoCmd.Close
End Sub

Then, in that code, put a page break on the DoCmd.Close line, and Access should allow you to debug the code, b/c you are closing the form, but not the whole application.
 
Okay, it's just weird.

I added the .Close code as you suggested, kjv1611, and REM'd out the other commands there. If I open the form and don't look through the records, I don't get the error, the form closes and the database remains open.

If I scroll through the records, I get the error, debug takes me to DoCmd.Close, and when I hit F8 the database closes.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top