If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Custom Error Messages
What i would like to be able to do is to customise the error messages that appear in Access.
For example when you create a Table and you specify that Required is set to True, if a user does not enter data into that field then a unfrendly error message appears. How can i change this? Does anybody also have any links to usefull websites on similiar topics. D |
#2
|
|||
|
|||
Custom Error Messages
You should have all of your data entry through forms. This allows you to
trap errors in the Form Error event. The first step is to add a message box in the form's error event that displays the error number and description. You can then handle these error numbers with your own messages. -- Duane Hookom MS Access MVP "DMc2004" wrote in message ... What i would like to be able to do is to customise the error messages that appear in Access. For example when you create a Table and you specify that Required is set to True, if a user does not enter data into that field then a unfrendly error message appears. How can i change this? Does anybody also have any links to usefull websites on similiar topics. D |
#3
|
|||
|
|||
Custom Error Messages
How I trap errors?
Is there a list of error codes around? "Duane Hookom" wrote: You should have all of your data entry through forms. This allows you to trap errors in the Form Error event. The first step is to add a message box in the form's error event that displays the error number and description. You can then handle these error numbers with your own messages. -- Duane Hookom MS Access MVP "DMc2004" wrote in message ... What i would like to be able to do is to customise the error messages that appear in Access. For example when you create a Table and you specify that Required is set to True, if a user does not enter data into that field then a unfrendly error message appears. How can i change this? Does anybody also have any links to usefull websites on similiar topics. D |
#4
|
|||
|
|||
Custom Error Messages
Here is some code that I have used in many apps for years. It is probably a
little dated since MsgBox() change in version 2000. There is a msgbox replacement function for 2000 and later at http://www.trigeminal.com/usenet/usenet015.asp?1033. Public Function FormOnError(pintDataErr As Integer) As Integer '================================================= ==================+ 'This function can be called from the On Error event of a form | ' to trap data errors such as input mask or invalid data | 'Allow Access to handle other types of errors such as referential | ' integrity, record locking etc. | 'To implement this function, use the following syntax | ' Private Sub Form_Error(DataErr As Integer, Response As Integer) | ' Response = FormOnError(DataErr) | ' End Sub | ' Programmer: Duane Hookom | ' Date: 10/29/1998 | ' Parameters: pintDataErr is the Form Error number | '================================================= ==================+ On Error GoTo FormOnError_Err Dim strErrMsg As String 'For Error Handling Const INPUTMASK_VIOLATION = 2279 Const DATAVALUE_VIOLATION = 2113 'bad date or too large of number or text in numeric Const LIMITTOLIST_VIOLATION = 2237 Const VALIDATION_VIOLATION = 2107 'violation of Validation Select Case pintDataErr Case INPUTMASK_VIOLATION, DATAVALUE_VIOLATION, LIMITTOLIST_VIOLATION, VALIDATION_VIOLATION Case Else 'Get out and let Access Handle all other errors FormOnError = acDataErrDisplay Exit Function End Select Dim strMsg As String Dim strCtlName As String Dim strCaption As String Dim strAccessError As String Dim strCurText As String Dim intReturn As Integer Dim ctrl As Control Set ctrl = Screen.ActiveControl intReturn = acDataErrContinue strCtlName = ctrl.Name strCurText = "The value entered" On Error Resume Next 'in case ctrl doesn't have a text property or Label strCurText = ctrl.Text If ctrl.Controls.Count 0 Then 'Get the label caption if present strCaption = ctrl.Controls(0).Caption End If On Error GoTo FormOnError_Err 'set error handling back on strAccessError = Application.AccessError(pintDataErr) Select Case pintDataErr Case VALIDATION_VIOLATION strMsg = "The value " & strCurText & " isn't a valid entry.@" & _ "The validation rule is: " & strCaption & " " _ & ctrl.ValidationRule & "." & vbCrLf & _ "Enter a valid value or press [Escape] to cancel your changes.@" Case INPUTMASK_VIOLATION Select Case Left(ctrl.InputMask, 10) Case "99/99/0000" strMsg = strCurText & " is an invalid date format." & _ "@All dates must contain the century 'm/d/yyyy'.@" Case Else strMsg = "An input mask violation occurred in control " strMsg = strMsg & strCtlName & "." & "@The text/numbers must " & _ "match the format " & ctrl.InputMask & ".@" End Select Case DATAVALUE_VIOLATION strMsg = strCurText & " is an incorrect value." & "@" & _ "For instance an invalid date or text in a " & _ "numeric field or value too large for the data field@" Case LIMITTOLIST_VIOLATION strMsg = strCurText & " is not in the list of options." & _ "@You must enter a value from the list.@" Case Else strMsg = "Form data error: " & pintDataErr & vbCrLf & strAccessError End Select Beep 'Get the user's attention MsgBox strMsg, vbInformation + vbOKOnly, strCaption & " Data Error" On Error Resume Next ' Select the full text ctrl.SelStart = 0 ctrl.SelLength = Len(ctrl.InputMask) FormOnError_Exit: FormOnError = intReturn Exit Function FormOnError_Err: Select Case Err Case Else strErrMsg = strErrMsg & "Error #: " & Format$(Err.Number) & vbCrLf strErrMsg = strErrMsg & "Error Description: " & Err.Description MsgBox strErrMsg, vbInformation, "FormOnError" Resume FormOnError_Exit End Select End Function -- Duane Hookom MS Access MVP -- "DMc2004" wrote in message ... How I trap errors? Is there a list of error codes around? "Duane Hookom" wrote: You should have all of your data entry through forms. This allows you to trap errors in the Form Error event. The first step is to add a message box in the form's error event that displays the error number and description. You can then handle these error numbers with your own messages. -- Duane Hookom MS Access MVP "DMc2004" wrote in message ... What i would like to be able to do is to customise the error messages that appear in Access. For example when you create a Table and you specify that Required is set to True, if a user does not enter data into that field then a unfrendly error message appears. How can i change this? Does anybody also have any links to usefull websites on similiar topics. D |
#5
|
|||
|
|||
Custom Error Messages
"=?Utf-8?B?RE1jMjAwNA==?=" wrote in
: How I trap errors? Is there a list of error codes around? In addition to Duane's catch-all error trapping, you can also use the BeforeUpdate event on the form to look for particular things: Private Sub Form_BeforeUpdate(Cancel As Integer) If IsNull(txtMyRequiredControl.Value) Then ' send the user to the right control txtMyRequiredControl.SetFocus ' tell him or her why MsgBox "You left RequiredControl empty!", etc ' and call off the update Cancel = True ElseIf DCount("*", "Payments", "PayerID = " & txtIDNumber.Value) _ =0 Then ' No payments? MsgBox "You haven't made any payments yet!" sfmPaymentsSubForm.SetFocus ' Cancel = True ElseIf etc.IsWrong Then Cancel = True End If ' if Cancel is still false then things must be okay, so ' just do nothing End Sub and so on. The other smart thing to do is to provide DefaultValues for all required fields -- because otherwise you can get unexpected errors when doing INSERT commands in SQL. Hope that helps Tim F |
Thread Tools | |
Display Modes | |
|
|