Errors when processing events (1 Viewer)

tucker61

Registered User.
Local time
Today, 02:57
Joined
Jan 13, 2008
Messages
321
I frequently get a error logged when people try to exit a particular form, when the form events are still processing. What is the easiest way to stop this, Is it something simple like disable the exit button until form event has finished ?
 

Minty

AWF VIP
Local time
Today, 10:57
Joined
Jul 26, 2013
Messages
10,371
I'd try and fix the error, if it's a time out problem look at what code is running on close and break it down to find where the delay is, and look at performance improvement.

If you can't see a specific issue remove the various parts of the closing routines and add them back one at a time until the problem returns.
 

Ranman256

Well-known member
Local time
Today, 05:57
Joined
Apr 9, 2015
Messages
4,337
If the form is processing code, users should not be able to exit.
What kind of errors?
 

tucker61

Registered User.
Local time
Today, 02:57
Joined
Jan 13, 2008
Messages
321
If the form is processing code, users should not be able to exit.
What kind of errors?
Today we have had over 100 people in and out of the database and only 2 have had error from my main page.. error code 2585. This action can't be carried out whilst processing a form or event.

The error has been triggered by the quit button on my main page, somi can only assume that during the forms loading, these 2 operators have decided they have gone into the wrong form and quit whilst the form was still loading..

Sent from my SM-T715 using Tapatalk
 

JHB

Have been here a while
Local time
Today, 11:57
Joined
Jun 17, 2012
Messages
7,732
I which event do you've the code?
Show the code.
 

tucker61

Registered User.
Local time
Today, 02:57
Joined
Jan 13, 2008
Messages
321
This is the code in question.

Code:
Private Sub btnQuit_Click()
On Error GoTo Handler
Dim LResponse As Integer
AttemptSave
   If IsNull(tbJobID) Or tbJobID = "" Then
        DoCmd.Close acForm, "frmMain"
        
        '''
    Exit Sub
   Else
        If (Nz(tbCatNo, "") = "") Then
            MsgBox "The Line Number box has been left Blank.!" & vbNewLine & "This Job will be deleted when you click Exit. ", vbOKOnly + vbExclamation, "Missing"
            Cancel = True
            WarningsOff
            tbCatNo = "DNull"
            Dim deljob As Long
            deljob = tbJobID
            Long_Name = DLookup("Long_Name", "tblqcusers", "User_Name='" & Environ("UserName") & "'")
            CurrentDb.Execute "INSERT INTO tblQCDeletedJobs ( Job_ID, User_Name, [Time], Raised_By, Line_Number) " & _
                              "SELECT " & deljob & " AS Expr1, '" & Long_Name & "' AS Expr2, Now() AS Expr3, '" & Raised_by & "' As Expr4, '" & tbCatNo & "' as Expr5;"
                If cboxStatus <> 13 Then
                cboxStatus = 14
                InsertStatus
                End If
            WarningsOn
            DoCmd.Close acForm, "frmMain"
            Exit Sub
            ElseIf (Nz(cboxStatus, "") = "0") And tbJobID <> "" Then
            LResponse = MsgBox("Status has been left Empty!" & vbNewLine & "Please change the Status or Request Deletion !", VBOkayOnly, "Continue")
            ESCMessage
            'cboxStatus.SetFocus
            Cancel = True
        Exit Sub
        Else
        End If
    
    If (Nz(tbJobID, 0) > 0) And ((Nz(cboxQueryType, "") = "") Or ((lblTitle.Caption <> "Rectification") And (Nz(cboxRequestArea, "") = "")) Or (Nz(cboxStockLoc, "") = "") Or (Nz(cboxSupplier, "") = "")) Then
     LResponse = MsgBox("You can't quit while you are entering a partially created job!" & vbNewLine & "Do you wish to continue ?", vbYesNo, "Continue")
            If LResponse = vbNo Then
            ESCMessage
            btnQuit.SetFocus
            Cancel = True
            cboxStatus = Nz(DLookup("Status_ID", "tblQCJobStatus", "Job_ID=" & Nz(tbJobID, 0) & " AND Status_Change=" & SQLDate(Nz(DMax("Status_Change", "tblQCJobStatus", "Job_ID=" & Nz(tbJobID, 0)), "1/1/1"))), 0)
            Exit Sub
            Else
            End If
End If
        CheckMandatoryFields
        'AttemptSave
        DoCmd.Close acForm, "frmMain"
End If
Exit Sub
Handler:
        Call LogError(Err.Number, Err.Description, "FRMmainBtnQuit", tbJobID)
        Forms!frmmain.Visible = True
        Exit Sub
End Sub
 

Minty

AWF VIP
Local time
Today, 10:57
Joined
Jul 26, 2013
Messages
10,371
The button Click event doesn't have a cancel event, so I'm slightly surprised you don't get errors more often.

In general this type of form validation is much better handled in the BeforeUpdate event which does have a cancel option that will allow the form to remain open, if it's attempted to be closed unexpectedly.

I would be tempted to store a lot of those dlookup values in hidden controls on the form, or set them as local constants, on the form load so you aren't dealing with them on close.

Your insert query may be taking some time if the table has a lot of indexes on it. It will probably run better if it were a saved query.

The whole thing looks overly complicated but without seeing the other codes e.g checkmandatoryfields and EscMessage it's difficult to be more specific.

Maybe a look at your data structure and a simple explanation of what the database is for (in plain English) would help.
 

missinglinq

AWF VIP
Local time
Today, 05:57
Joined
Jun 20, 2003
Messages
6,423
And just to be sure, before doing any more thinking on the subject...this database has been split, with each user having their own copy of the front end on their PC, and all data in a single file on a shared folder, correct?

Linq ;0)>
 

tucker61

Registered User.
Local time
Today, 02:57
Joined
Jan 13, 2008
Messages
321
And just to be sure, before doing any more thinking on the subject...this database has been split, with each user having their own copy of the front end on their PC, and all data in a single file on a shared folder, correct?

Linq ;0)>
Correct..

Sent from my SM-T715 using Tapatalk
 

Users who are viewing this thread

Top Bottom