Access Exit behaves differently depending on how it is run

pledbetter

Registered User.
Local time
Today, 15:59
Joined
Feb 20, 2012
Messages
16
I have an application called "MCLAP4". In the Access Options-Current Database-Application Options, I have the "Display Form:" set to "login screen". That is an existing form that works fine. On one of my forms, I have an "Exit" command button. The "On-Click" property of that form is the following VBA code:
Private Sub Command3_Click()
DoCmd.Quit acQuitSaveAll

End Sub

When I run the application as an application, and I click the "Exit" button, I get the following error: "MCLAP4 cannot find the referenced form 'login screen'.
When I run the application from design mode, starting from the form "login screen", and then go to the form with the Exit button, and then click that same Exit button, I get no such error, and Access exits cleanly.
Why does the same code behave differently depending on how Access is run, how can I get it to exit cleanly in application mode, and why is it looking for this form? By the way, I even loaded the form "login screen" in hidden mode and I still got the same symptoms.

Attached is a screen shot of the error
 

Attachments

Is there code in the load event of that form referring to the login form?
 
"Login Screen" is the first form to load.

"Login Screen"'s OnLoad Event goes like this:

Private Sub Form_Load()
Call SetSwitchboardScreen
End Sub

which calls


Sub SetSwitchboardScreen()
strSwitchboard = "Switchboard"
End Sub


I'm just initializing setting a global variable
 
I meant the form with the quit code.
 
Hear is what happen "On Load"


Private Sub Form_Load()
Call ClearAllAppts
DoCmd.GoToControl "Combo114"
Call SetSwitchboard1Screen

End Sub


Function ClearAllAppts()
On Error GoTo ClearAllAppts_Err
DoCmd.SetWarnings False
If (DCount("user", "[qryCountAllUserAppointments]") >= 1) Then
DoCmd.OpenQuery "qryResetAllUserAppointments", acViewNormal, acEdit
End If
DoCmd.OpenQuery "CPAllApptsCredit", acViewNormal, acEdit
DoCmd.OpenQuery "CPAllApptsCreditAnalyst", acViewNormal, acEdit
DoCmd.OpenQuery "CPAllApptsCSR", acViewNormal, acEdit
DoCmd.OpenQuery "CPAllApptsFinance", acViewNormal, acEdit
DoCmd.OpenQuery "CPAllApptsREAgent", acViewNormal, acEdit
DoCmd.SetWarnings True

ClearAllAppts_Exit:
Exit Function
ClearAllAppts_Err:
MsgBox Error$
Resume ClearAllAppts_Exit
End Function

Sub SetSwitchboard1Screen()

strSwitchboard = "Switchboard1"

End Sub
 
Do any of the queries reference it?
 
A bunch do. But none of them are running when I try to exit. In fact, for my test, I start the app, which loads Login Screen, I log in, it closes Login Screen and takes me to a form called "Switchboard", and I immediately click the "Exit" button. No other queries are running when I click exit. Remember, it exits fine when Login Screen is started from Developer mode.
 
acQuitSaveAll cannot be applied to an accde.

This is to save the object designs and is only applicable in design mode.
 
1.
And cross posted at: http://www.utteraccess.com/forum/Access-Find-Nonexistent-t2009762.html

By the way, unless Microsoft have changed the Cancel behaviour of Forms after A2003, Brent's code in post #3 on the above link won't work. The Form Unload event can't be cancelled after a VBA Quit command is issued. People have to get used to the idea that the VBA Quit command is NOT the same as the X or via the File menu. It is brutal, it is not a request it is an instruction.

----------

2.
Some of the code indicates that a Global variable is holding the name of a Form. Unless a person is aware of the possibility, global variables should not be used in, or code called by, Form/Report Close or Unload events. The VBA Quit command will reset global variables BEFORE those events are run. (Let's see how long that one takes to trickle into common knowledge. :rolleyes: )

----------

3.
Okay, I'll be the bunny and ask the question; what is the difference between application mode and developer mode?


Chris.
 
Galaxiom: I am running a accdb, not a accde

Alansidman: I do not understand the purpose of the cross-post. I posted the same question on 4 forums to try to get an answer more quickly.

ChrisO: I'm not using that Global variable in any Close/Unload events. I apologize for my impreciseness, but the exact terminology escapes me for the moment. What I am calling "Application" mode is when you double-click on the accdb file and the application runs. What I'm calling "Developer" mode is when you hold the shift key down and click the accdb file, and you are presented with all the database objects that you can open in Design View or whatever available mode you wish.
 
So far, the best workaround is to forcibly re-open "Login Screen" just before exiting the application. This in my opinion is a weak solution and does not address the root cause. I am still looking for an actual solution.
 
A bunch do. But none of them are running when I try to exit.

None of them are running, or none of them should be running? I've had experience with a bug/quirk where quitting the application caused code in the load event to be fired. I got a similar error about not being able to find the login form. In my case I got around it with error trapping.

By the way, to Alan's point about cross posting:

http://www.excelguru.ca/node/7
 
OK, point taken about cross posting. Sorry. I didn't know. I'll follow the guidelines from now on.

I'm relatively new to forum posting but not new to Access development. I'm 99% sure no other queries are running.

On the form on which is the Exit button that I am trying to get to execute, there is a label whose data source is on the Login Screen form:

="Appts for " & [Forms]![login screen]![user]

Ignoring for the time being that it makes no sense to me why a data source has to be present before a form can be closed, it is the inconsistency of the appearance of this error that really puzzles me. If the data source of a label is the root cause of the problem, it should make no difference how the application is launched. The error should appear regardless.
 

Users who are viewing this thread

Back
Top Bottom