Why does Access 2010 Quit Button Throw Error (1 Viewer)

ppierce

Registered User.
Local time
Today, 01:51
Joined
Nov 18, 2009
Messages
21
I have and Access 2010 application with 3 forms each form has a button that will close the database. The code for all three buttons is identical and looks like this

Code:
Private Sub cmdQuit_Click()
DoCmd.SetWarnings False
Dim SQL As String
SQL = "Delete from CallTakerData"
DoCmd.RunSQL SQL
DoCmd.Quit
End Sub
All of these work as expected until I save the database as an accde file. When I do that one of the buttons pops this error message:
The Expression On Load you entered as the event property setting produced the following error: "There was a problem referencing a property or method of an object."
This is my code for the form Onload:
Code:
Private Sub Form_Load()
Me.OperName = DLookup("CallTaker", "QueryCallTaker")
Me.OperEID = DLookup("EID", "QueryCallTaker")
End Sub
The Onload does not have an error when the form loads and I have placed a breakpoint on the OnLoad code block and when I click the Quit Button the Onload is not run.
Anyone have an idea why this one form is having this problem with this one form?


 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:51
Joined
Oct 29, 2018
Messages
21,542
Hi. I would suggest adding an error handler anyway, so you can get a better clue when you run it as ACCDE.
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 22:51
Joined
Aug 30, 2003
Messages
36,133
I had a somewhat similar problem with an app where the load event of a form was running when I quit. In my case the load event had a line referring to a login form, which had already been closed when the application was quitting. I could never figure out why the load event was running, nor could anyone I asked. I got around it by adding a case for the specific error in the load event's error handler:

Code:
ExitHandler:
  Exit Sub

ErrorHandler:
  Select Case Err
    Case 2450
      'strange error of form load code running on quit
      DoCmd.Hourglass False
      Resume ExitHandler
    Case Else
      MsgBox Err & Err.Description & " in Reservation Form_Load "
      DoCmd.Hourglass False
      Resume ExitHandler
  End Select
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 15:51
Joined
Jan 20, 2009
Messages
12,856
I had a somewhat similar problem with an app where the load event of a form was running when I quit. In my case the load event had a line referring to a login form, which had already been closed when the application was quitting.

I have similar problems in Excel if the user closes Excel without closing the workbook first. Code on events that shouldn't even be running throw errors about not being able to find a member because the controls have apparently already unloaded.

They are ActiveX controls on the worksheet itself. It isn't a problem of the controls and code are on a user form.

I even tried using a variable to avoid running the code except in specific circumstances and still got the error when the variable should have avoided the code. I think it is a compile error rather than actually executing the code.

Beats me why it does this check as the application quits.
 

Micron

AWF VIP
Local time
Today, 01:51
Joined
Oct 20, 2018
Messages
3,478
By any chance do your code modules NOT have Option Explicit at the top of each (under Option Compare Database)? Making the db an accde would compile your code, in which case you could experience a failure whereas you might not otherwise. Failure to set that option and the existence of an undeclared variable will also not usually be found until run time.

Also, you might be using ! where you should be using . as in Me!txtSomeTextbox and the reference following ! is spelled wrong. That will never be found when compiling - only at run time.
 

ppierce

Registered User.
Local time
Today, 01:51
Joined
Nov 18, 2009
Messages
21
Thanks for all of the suggestions, however none of them solved the problem. I was able to locate the cause of the error but not a fix. The error message only shows if I deselect the Display Navigation Pane in the Current Database Options. If I leave that checked the Quit functions runs without the error. So I just removed all items from the Navigation Pane.
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 22:51
Joined
Aug 30, 2003
Messages
36,133
Can you attach the db here? I'm surprised the error handler didn't work, and I always deselect the Display Navigation Pane option.
 

ppierce

Registered User.
Local time
Today, 01:51
Joined
Nov 18, 2009
Messages
21
Here you go. I removed the error handler code.

I have never uploaded anything to the forum so hope the file was included.
 

Attachments

  • CADEventForm.accdb
    1.1 MB · Views: 68

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 22:51
Joined
Aug 30, 2003
Messages
36,133
I created an accde and the quit button from all 3 forms worked without error. Is there a particular sequence required to get the error?
 

ppierce

Registered User.
Local time
Today, 01:51
Joined
Nov 18, 2009
Messages
21
Publish the database as an accde file and in the options clear the checkbox for show navigation pane. Note I am using MS Access 2010.
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 22:51
Joined
Aug 30, 2003
Messages
36,133
Ah forgot that. Error handling does handle it, just don't include a message box.
 

ppierce

Registered User.
Local time
Today, 01:51
Joined
Nov 18, 2009
Messages
21
So this code should work?

Code:
ExitHandler:
  Exit Sub

ErrorHandler:
  Select Case Err
    Case 2450
      'strange error of form load code running on quit
      DoCmd.Hourglass False
      Resume ExitHandler
    Case Else
            DoCmd.Hourglass False
      Resume ExitHandler
  End Select

And where exactly would I put this code. In my original attempt I just pasted it at the bottom of my code screen, below the VB functions.
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 22:51
Joined
Aug 30, 2003
Messages
36,133
In the load event. Since you're not putting up a message box for any error, simply:

Code:
Private Sub Form_Load()

    On Error GoTo ErrorHandler

    Me.OperName = DLookup("CallTaker", "QueryCallTaker")
    Me.OperEID = DLookup("EID", "QueryCallTaker")

ExitHandler:
    On Error Resume Next
    Exit Sub

ErrorHandler:
    Select Case Err
        Case Else
            DoCmd.Hourglass False
            Resume ExitHandler
    End Select
End Sub

You could even get rid of the Select/Case, it's a holdover from handling different errors.
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 22:51
Joined
Aug 30, 2003
Messages
36,133
No problem. This drove me crazy when it happened to me, and nobody could figure out why the load event was running at that point.
 

Users who are viewing this thread

Top Bottom