Application.Quit / DoCmd.Quit Fails

A

Ajandco

I have a problem very similar to one recently described on Access Monster. A
solution was proposed that apparently worked. Unfortunately my command of
VBA is not yet up to the previously answer.

My database opens using a shortcut from the desktop to FrmStartup. FrmStartup
form calls another routine which does some calculations then tries to exit
the application. The application appears to close however, unfortunately a
copy of Access shows up in the processes list for each time I open and close
the application and doesn't appear in the applications list. While this in
itself doesn't cause any problems, whenever the screensaver cuts in during
the day, each hidden copy of Access that was 'running' causes a "Microsoft
Access has experienced a problem...". not a very elegant screen for users to
open up to, 4 or five failed application occurances!

I know the shortcut is part of the problem - if I open the database by
specifying FrmStartup in the Tools Startup Options the problem does not occur.
Unfortunately I have other reasons for starting the database using the
shortcut and I need to keep the current startup method.

The solution that was described previously was "parameter for LoadForm
defined as ByRef (or not declared,which is implicitly ByRef)? Try doing it
with ByVal" is a bit obscure to me.

The FrmStartup coding (which fails to properly close down Access) is simply:

Option Compare Database

Private Sub Form_Open(Cancel As Integer)
Call CalculationRoutine 'the calculations are carried out here
Do Until Forms.Count = 0
DoCmd.Close acForm, Forms(0).Name
Loop
DoCmd.Quit acQuitSaveNone
End Sub

Could you please oblige by giving me an idea as to how to apply the solution
previously described?

Many thanks

Alastair
 
G

Guest

Try this:

Private Sub Form_Open(Cancel As Integer)
Call CalculationRoutine 'the calculations are carried out here
DoEvents 'passes control to windows so it can complete pending processes
Do Until Forms.Count = 0
DoCmd.Close acForm, Forms(0).Name
Loop
DoCmd.Quit acQuitSaveNone
End Sub

Steve
 
G

George Nicholson

Question: Once a form closes, will any code on that form continue to run?

i.e., since this is in a Form module and all Forms have been closed, will
DoCmd.Quit even execute??

The OP said it works if FrmStartup is set as the startup form, but not if
frmStartup is specified in a shortcut command line, so I guess it does
execute, but I'm at a loss to explain how this works at all as written.
 
G

Guest

Question: Once a form closes, will any code on that form continue to run?

Good point. Hadn't thought of that! I wouldn't expect it to run but if the
OP is explaining the scenario correctly, it does appear to be...sometimes,
unless I am misunderstanding his explanation.

I'd be ineterested to know what exactly is going on. If the DB is just
running some code then closing it would probably be better to use an AutoExec
macro or something similar.

I don't understand why the form can't just be made the startup form...

Steve
 
D

David W. Fenton

Ajandco said:
The solution that was described previously was "parameter for
LoadForm defined as ByRef (or not declared,which is implicitly
ByRef)? Try doing it with ByVal" is a bit obscure to me.

That was a completely different context, where a subroutine was
being used to open the form, and simply doesn't apply here.

Does your app have a startup form or an AutoExec? I expect it
doesn't, but if it does, you could use the /cmd switch and then have
your startup code use the COMMAND statement to see if anything was
passed, and then open the form you're using for processing, instead
of the regular startup.

If you *don't* have a startup routine, you could make the form
you're trying to open your startup form, and if the /cmd argument is
not supplied, don't execute the code at all, and simply close the
form.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top