Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old June 7th, 2007, 04:22 PM
Friend of Wrox
 
Join Date: Apr 2006
Location: Ternat, , Belgium.
Posts: 159
Thanks: 0
Thanked 0 Times in 0 Posts
Default data type error message

hi,

got a question. When on a form I format a text box to for exemple 'short date' I get an error message to tell me if the format is wrong.

So here I have to input something like 10:00. If the users try to input 10h00 (what can be a notation here in Belgium), the error message appears. Now what I would like to know if it is possible to intercept this message and change it so it would be more clear to understand for the user...

Don't know if this is clear for you and if this can be done... By the way, this is on an unbound form (don't know if this is important here).

  #2 (permalink)  
Old June 8th, 2007, 08:00 AM
Friend of Wrox
Points: 4,007, Level: 26
Points: 4,007, Level: 26 Points: 4,007, Level: 26 Points: 4,007, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

In your data table, there are properties for that field called "Validation Rule" and "Validation Text." The rule sets what the user should be typing in. The text sets what error message the user sees if he or she violates the rule. That's where you put your simple error message.

The other way to do it is to know what error number you get with the error, and then use error trapping in your VBA and say

If Err.Number = xxxx Then
    MsgBox "Custom Error Message Here", vbCritical, "Data Entry Error!"
Else
    MsgBox Err.Description, vbCritical, "Error " & Err.Number
End If

Where xxxx is the actual error number you see when it fails.


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
  #3 (permalink)  
Old June 9th, 2007, 04:11 PM
Friend of Wrox
 
Join Date: Apr 2006
Location: Ternat, , Belgium.
Posts: 159
Thanks: 0
Thanked 0 Times in 0 Posts
Default

On the second one, with the vba, I guess it has to be put on the 'form error' event?

For the first one, do I have to give in a 'validation rule' for the 'validation text' to work? Or if I fill in the validation text, will it take this tekst for that particular error?

Thanks already

  #4 (permalink)  
Old June 11th, 2007, 06:50 AM
Friend of Wrox
Points: 4,007, Level: 26
Points: 4,007, Level: 26 Points: 4,007, Level: 26 Points: 4,007, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

For the first one, the validation error only works if you put a validation text in. They go together.

For the second, if you put it on the ON ERROR event, then ANY error happening in ANY procedure will default to that event. However, if you want SPECIFIC errors for EACH event (e.g. ON CURRENT, ON OPEN, NameOfControl_AFTERUPDATE, etc.) then you don't put it there. You place it in the specific event itself. For example, suppose you have textbox AfterUpdate event. It'd look something like this:

Private Sub MyTextBox_AfterUpdate()

    On Error GoTo Err_MyTextBox_AfterUpdate

    'Your code here.

Exit_MyTextBox_AfterUpdate:
    Exit Sub

Err_MyTextBox_AfterUpdate:
    If Err.Number = xxxx Then
        MsgBox "Custom Error Message Here", vbCritical, "Error " & Err.Number
    Else
        MsgBox Err.Description, vbCritical, "Error " & Err.Number
    End If
    Resume Exit_MyTextBox_AfterUpdate

End Sub

Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division


Similar Threads
Thread Thread Starter Forum Replies Last Post
Parser Error Message: Could not load type '_Defaul sahmed1983 VB Databases Basics 1 January 25th, 2007 09:12 AM
Compiler Error Message: CS0246: The type or namesp frmsasp All Other Wrox Books 0 September 17th, 2005 09:13 AM
Error message: old format or invalid type library kaz .NET Framework 2.0 2 October 6th, 2004 12:39 PM
Data Type error but it is the correct type Mitch SQL Server 2000 2 March 19th, 2004 11:31 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.