Exit Sub when in a sub routine (1 Viewer)

tucker61

Registered User.
Local time
Today, 02:05
Joined
Jan 13, 2008
Messages
321
I have the following code on my Quit Button.

which calls the Private sub to check for deleted Jobs.


Code:
Private Sub BtnQuit_Click()
On Error GoTo handler
Dim LResponse As Integer
DoEvents
AttemptSave

If Me.FilterOn = True Then
Me.FilterOn = False
End If

   If IsNull(tbJobID) Or tbJobID = "" Then
        DoCmd.Close acForm, "frmMain"
   Exit Sub
   Else
   [COLOR="RoyalBlue"]Call delete_job[/COLOR]

    CheckMandatoryFields
    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

When i run the Deleted jobs code, this prompts the users for a response if they want to continue. If the user clicks No, the code Exits, and then goes back to the calling procedure and closes the form down.

How do i change the code to Stop the form from closing if the user clicks NO ?

PS i call this Delete Job code from multiple routines, so i cant move the Close for code into this routine.


Code:
Private Sub delete_job()
On Error GoTo handler
Dim SearchJob As String
Dim JobHold As Long
Dim LResponse As Integer
Dim deljob As Long
Dim strsql As String

If IsNull(cboxStatus) Then
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)
End If

JobHold = Nz(tbJobID, 0)

If Not NewRecord Then
If cboxStatus = "1" Or cboxStatus = "" Or cboxStatus = "0" Or cboxStatus = "14" Then
            LResponse = MsgBox("Job is not Completed!" & vbNewLine & "Do you wish to continue with the Search / Exit ?" & vbNewLine & "Current Job will be deleted.", vbYesNo, "Continue")
                
[COLOR="Blue"]                If LResponse = vbNo Then
                cboxStatus.SetFocus
                Cancel = True
                Exit Sub[/COLOR]
                Else
                WarningsOff

                deljob = tbJobID
                CurrentDb.Execute "INSERT INTO tblQCDeletedJobs ( Job_ID, User_Name, [Time], Raised_By, Line_Number) " & _
                                  "SELECT " & deljob & " AS Expr1, '" & Environ("UserName") & "' AS Expr2, Now() AS Expr3, '" & Raised_by & "' As Expr4, '" & Cat_No & "' as Expr5;"
                WarningsOn
                End If
    End If


If IsNull(tbCatNo) Or (Nz(tbCatNo, "") = "") Then
 If IsNull(tbJobID) Or (Nz(tbJobID, "") <> "") Then
    Else
WarningsOff
cboxStatus = 14
InsertStatus
        deljob = tbJobID
        CurrentDb.Execute "INSERT INTO tblQCDeletedJobs ( Job_ID, User_Name, [Time], Raised_By, Line_Number) " & _
                          "SELECT " & deljob & " AS Expr1, '" & Environ("UserName") & "' AS Expr2, Now() AS Expr3, '" & Raised_by & "' As Expr4, '" & Cat_No & "' as Expr5;"
        WarningsOn ''
    End If
End If
End If
Exit Sub
handler:


        Call LogError(Err.Number, Err.Description, "11", tbJobID)
        Forms!frmMain.Visible = True
        Exit Sub

        

End Sub
 

Gasman

Enthusiastic Amateur
Local time
Today, 09:05
Joined
Sep 21, 2011
Messages
14,050
Change it to a function and return the response.?
Declare a global variable, set to false/true before the call and test on return?
 

Users who are viewing this thread

Top Bottom