ValidationText msgbox

G

Guest

Hello,

I know for a control, u have the ValidationRule & ValidationText properties
to validate data & I know how they work.

Is their any way to change the type of Msgbox that appears if the
ValidationText is triggered ? As an example to include vbCritical so the Red
X appears ?

I know their are other ways to trap invalid data being entered & it can be
done there but what I would like to know is only through the ValidationText
way.

Any help would be greatly appreciated.

Thank you,
Jeff
 
D

Dirk Goldgar

Jeff said:
Hello,

I know for a control, u have the ValidationRule & ValidationText
properties to validate data & I know how they work.

Is their any way to change the type of Msgbox that appears if the
ValidationText is triggered ? As an example to include vbCritical so
the Red X appears ?

I know their are other ways to trap invalid data being entered & it
can be done there but what I would like to know is only through the
ValidationText way.

I didn't think so, but I just found a way. It's a bit cumbersome, and I
don't know if it can be relied on to work in all circumstances, but you
can play with it and see.

It looks to me like the validation error is number 7753. If this can be
relied on, you can use the form's Error event to trap that error and
display the ValidationText from the active control, which ought to be
the one that raised the error:

'----- start of sample code -----
Private Sub Form_Error(DataErr As Integer, Response As Integer)

If DataErr = 7753 Then
MsgBox Me.ActiveControl.ValidationText, _
vbCritical, "Invalid Entry"
Response = acDataErrContinue
Else
Response = acDataErrDisplay
End If

End Sub

'----- end of sample code -----
 
G

Guest

Hi Dirk,

Thank you, your idea is a good one. I never knew that triggers that form
Err. Do you have a list by any chance of all the Err Codes & what they
corespond to that can be triggered in the Form Err Event ?

I am used to Err # 2113 for invalid Input Masks.

Thanks a bunch,
Jeff
 
D

Dirk Goldgar

Jeff said:
Hi Dirk,

Thank you, your idea is a good one. I never knew that triggers that
form Err. Do you have a list by any chance of all the Err Codes &
what they corespond to that can be triggered in the Form Err Event ?

I am used to Err # 2113 for invalid Input Masks.

If you paste the following function into a standard module and run it,
it will create a table of Access and Jet error codes and their stored
descriptions. Note that the descriptions often contain placeholders for
information to be filled in at run time -- sometime they consist almost
solely of such placeholders.

This code is modified only slightly -- to increase the range of error
numbers, and to disambiguate the declarations of DAO objects -- from
code that was published in the help file for Access 97. Watch for line
wraps introduced by the newsreader.

'----- start of code -----
Function AccessAndJetErrorsTable() As Boolean

Dim dbs As DAO.Database, tdf As DAO.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 15000
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
'----- end of code -----
 

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