Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Quit without message

Status
Not open for further replies.

debbieg

Technical User
Dec 2, 2002
190
US
I have an unbound field on my main form that has to be entered if they are going to use the database. A message appears if they don't fill it in. I do not want to see this message if exiting the application. How can I override this? I've tried the following:

Private Sub cmdExit_Click()
On Error GoTo Err_cmdExit_Click
Application.Quit acQuitSaveNone

Exit_cmdExit_Click:
Exit Sub

Err_cmdExit_Click:
MsgBox Err.Number & vbCrLf & Err.Description
Resume Exit_cmdExit_Click
End Sub

Private Sub txtBeginDate_Exit(Cancel As Integer)
Dim ctl As Control

If Screen.ActiveControl.Name = "cmdExit" Then
DoCmd.CancelEvent
cmdExit_Click
Exit Sub
ElseIf IsNull(txtBeginDate) Then
On Error Resume Next
For Each ctl In Me.Controls
ctl.Enabled = False
Next
cmdExit.Enabled = True

msg1 = "You must enter the current school year."
style = vbCritical
response = MsgBox(msg1, style, conTitle)
DoCmd.GoToControl "txtBeginDate"
Else
On Error Resume Next
For Each ctl In Me.Controls
ctl.Enabled = True
Next
End If
End Sub

Thanks for any help.
Debbie
 
add one more end if to the end of your sub. You forgot to end the Main If statement is this post:
Private Sub txtBeginDate_Exit(Cancel As Integer)
Dim ctl As Control

If Screen.ActiveControl.Name = "cmdExit" Then
DoCmd.CancelEvent
cmdExit_Click
Exit Sub
ElseIf IsNull(txtBeginDate) Then
On Error Resume Next
For Each ctl In Me.Controls
ctl.Enabled = False
Next
cmdExit.Enabled = True

msg1 = "You must enter the current school year."
style = vbCritical
response = MsgBox(msg1, style, conTitle)
DoCmd.GoToControl "txtBeginDate"
Else
On Error Resume Next
For Each ctl In Me.Controls
ctl.Enabled = True
Next
End If
End Sub
change to:
Code:
Private Sub txtBeginDate_Exit(Cancel As Integer)
    Dim ctl As Control
    
    If Screen.ActiveControl.Name = "cmdExit" Then
        DoCmd.CancelEvent
        cmdExit_Click
        Exit Sub
    ElseIf IsNull(txtBeginDate) Then
        On Error Resume Next
        For Each ctl In Me.Controls
            ctl.Enabled = False
        Next
        cmdExit.Enabled = True
   
        msg1 = "You must enter the current school year."
        style = vbCritical
        response = MsgBox(msg1, style, conTitle)
        DoCmd.GoToControl "txtBeginDate"
    Else
        On Error Resume Next
        For Each ctl In Me.Controls
            ctl.Enabled = True
        Next
    End If
[red]End If[/red]
End Sub


HTH
Mike

[penguin] Dooobie...Doobie......Dooo
 
If I add that I get an error. I only have 1 if statement.

The problem is with this code:


If Screen.ActiveControl.Name = "cmdExit" Then
DoCmd.CancelEvent
cmdExit_Click
Exit Sub
ElseIf IsNull(txtBeginDate) Then
On Error Resume Next
For Each ctl In Me.Controls
ctl.Enabled = False
Next
cmdExit.Enabled = True

msg1 = "You must enter the current school year."
style = vbCritical
response = MsgBox(msg1, style, conTitle)
DoCmd.GoToControl "txtBeginDate"

I get the message when I want to exit the application. If I'm exiting I don't care if the txtBeginDate is blank.

Thanks,
Debbie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top