Substituting a more user friendly error message

  • Thread starter John S. Ford, MD
  • Start date
J

John S. Ford, MD

I'm using Access 97.

I have an entry form that requires users to input several dates in some
TextBoxes. If the user enters data not in an acceptable date format, an
Access error message pops up that is not very user friendly. Is there a way
I can substitute my own (hopefully kinder, gentler message) for the standard
message?

Does this action by my user trigger an Error Event that I can capture and
write my own error handler? If so how?

John
 
S

Squirrel

John,

Access leaps in to ensure dates are entered correctly - perhaps you're using
an
input mask? Anyway, I don't know how to 'get in' first. I use a label
beside my date
fields ie. " mm/dd/yyyy " to show the user what is required. Then at least
they have some
idea of what is wrong when Access displays its message.

I'll check the board tomorrow to see if someone wiser can answer your
question. :)

Linda
 
R

Roger Carlson

You can do this in the On Error event of the FORM. Put something like the
following in the event:

'-----------------------------
Private Sub Form_Error(DataErr As Integer, Response As Integer)
If DataErr = 2279 Then '**not formatted for input mask**
MsgBox "The number is not formatted properly"
ElseIf DataErr = 2213 Then '**not a real date**
MsgBox "The number is not a real date"
Else
MsgBox DataErr
End If
Response = acDataErrContinue
End Sub
'-----------------------------

You can trap any number of form level errors here.

--
--Roger Carlson
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L
 
J

Joe Williams

Is there a list of the error codes somewhere so that you can know what error
numbers to trap for? Or, alternatively, if you get an error from access, is
there a way to know what error code that translates to?

- joe
 
D

Douglas J. Steele

The AccessError method will return a description of the error, given the
error number.

Here's code from the Help file:

The following procedure creates a table containing many of the error codes
and strings used or reserved by Microsoft Access and by the Microsoft Jet
database engine. Not all error codes are included in the resulting table, as
some exist outside the range of error codes evaluated by this procedure (0
to 4500).

Function AccessAndJetErrorsTable() As Boolean
Dim dbs As Database, tdf As TableDef, fld As DAO.Field
Dim rst As DAO.Recordset, lngCode As Long
Dim strAccessErr As String
Const conAppObjectError = "Application-defined or object-defined error"

On Error GoTo Error_AccessAndJetErrorsTable
' Create Errors table with ErrorNumber and ErrorDescription fields.
Set dbs = CurrentDb
Set tdf = dbs.CreateTableDef("AccessAndJetErrors")
Set fld = tdf.CreateField("ErrorCode", dbLong)

tdf.Fields.Append fld
Set fld = tdf.CreateField("ErrorString", dbMemo)
tdf.Fields.Append fld

dbs.TableDefs.Append tdf
' Open recordset on Errors table.
Set rst = dbs.OpenRecordset("AccessAndJetErrors")
' Loop through error codes.
For lngCode = 0 To 3500
On Error Resume Next
' Raise each error.
strAccessErr = AccessError(lngCode)
DoCmd.Hourglass True
' Skip error numbers without associated strings.
If strAccessErr <> "" Then

' Skip codes that generate application or object-defined errors.
If strAccessErr <> conAppObjectError Then
' Add each error code and string to Errors table.
rst.AddNew
rst!ErrorCode = lngCode
' Append string to memo field.
rst!ErrorString.AppendChunk strAccessErr
rst.Update
End If
End If
Next lngCode
' Close recordset.
rst.Close
DoCmd.Hourglass False
RefreshDatabaseWindow
MsgBox "Access and Jet errors table created."

AccessAndJetErrorsTable = True

Exit_AccessAndJetErrorsTable:
Exit Function

Error_AccessAndJetErrorsTable:
MsgBox Err & ": " & Err.Description
AccessAndJetErrorsTable = False
Resume Exit_AccessAndJetErrorsTable
End Function


Note that that code uses DAO. If you're using Access 2000 or 2002, you may
have to go into Tools | References and select the Microsoft DAO 3.6 Object
Library if you haven't already done so.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top