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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error 2169 default message

Status
Not open for further replies.

WalkieTalkie

Technical User
Feb 15, 2002
91
0
0
NZ
Essentially, I want to replace the default MS error message that comes up in response to err.number 2169, but am having a ridiculous amount of trouble with it!

I want to add some error handling to a form that will deal with the user who tries to close the form using the top right hand x button without having entered the employee number in the subform. Currently, I have got it so that when this happens, a custom error message comes up saying "You must enter employee number". The only option is an OK button. Then my custom message comes up saying "If you close this now you will lose the data. Click cancel if you don't want to close". OK and Cancel buttons. When the user click OK, the form closes fine - everything's sweet. But when the user clicks cancel, to try and return to the form, the confounded default message pops up as well. ("You can't save this record at this time...") Here is my code:

Code:
Private Sub Form_Error(DataErr As Integer, Response As Integer)
Select Case DataErr
Case 3101
    DoCmd.Beep
    MsgBox "You must enter or select an employee name", , "Sorry - this record has no name."
    Me.cmbEmployeeNo.SetFocus
    Response = acDataErrContinue

Case 2169
    If MsgBox("This form will close.@The data you have entered will not be saved." & Chr(10) & "Select Cancel if you do not want this form to close@@19@@2", vbOKCancel, "Sorry - can't save this record") = vbCancel Then
    Me.cmbEmployeeNo.SetFocus
    Exit sub
    Else
    Response = acDataErrContinue
    End If
End Select
End Sub
Why am I having so much trouble with this? What am I missing? Any help will be appreciated.
Regards
Miranda
 
Heres an easier method to achieve your objective, rather than a solution to your problem....

I'm assuming you use Access 2k or higher?

Use the form UnLoad event and use the Cancel parameter to prevent the close. You can then put a simple message box in allowing the user to choose their option.

For example:

txtID is my key field that needs to be entered...


Code:
Private Sub Form_Unload(Cancel As Integer)

    If txtID <> &quot;&quot; Then
     Cancel = 0
    Else
     Cancel = -1
    End If

End Sub

This is rather powerful code so use with caution.. if you dont allow the cancel to be set to backto 0 then the form wont close... cold re-boot comes to mind!!

HTH's
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top