Wrox Programmer Forums
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access 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
 
Old March 1st, 2004, 10:54 AM
bph bph is offline
Friend of Wrox
 
Join Date: Dec 2003
Posts: 102
Thanks: 2
Thanked 0 Times in 0 Posts
Default System messages

I get a system generated Access message that appears whenever I leave a specific textbox that requires an entry.

What can I do to make that message more user friendly? It doesn;t have an error number associated with it.

It's some verbage about a null value.

thanks, Bph

 
Old March 1st, 2004, 12:20 PM
Authorized User
 
Join Date: Dec 2003
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You can write a routine on the after_update property of the control.

The routine will check for a value and send a message if the value is null.

Also, you can use validate and message in the properties of the control...this doesn't allow as much customizing.

J

 
Old March 1st, 2004, 12:37 PM
bph bph is offline
Friend of Wrox
 
Join Date: Dec 2003
Posts: 102
Thanks: 2
Thanked 0 Times in 0 Posts
Default

J -- I need to replace the message coming from access. It's too verbose. The message occurs when the user moves from the control to another control on the form.

It says: The field 'X' cannot contain a Null value because the Required property for the field is set to true. Enter a value in this field.

I want to intercept that message and change to something like "You need to enter your intials before proceeding"

thx, bph

 
Old March 1st, 2004, 01:11 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 174
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Trap it on the Form's On Error event. To determine an error number, use this in the error handler routine:

Code:
MsgBox "Error #:" & err.number & chr(13) & chr(10) & "Description: " & err.Description,,"Error.."
Regards,

Beth M
 
Old March 1st, 2004, 01:52 PM
Friend of Wrox
 
Join Date: Jun 2003
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

BPH,

J is correct. Assuming your initals textbox is called "Initials", go to the textbox's AfterUpdate event and put something like:

Code:
   If IsNull(Me.Initials) Then
      MsgBox "You need to enter your intials before proceeding.", vbExclamation, "No Initials!"
      Me.Initials.SetFocus
   End If

Beth, BPH shouldn't put that code in the Form's On Error event because then ANY error will cause that specific error message to show. The error could happen anywhere on the form. If BPH wants a specific error message to show for that specific textbox, then it has to be done on the specific control's AfterUpdate event.


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old March 1st, 2004, 02:00 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 174
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Greg,

Actually, if you have a required field that is being left blank, you can trap any and all on the Before_Update of the form, the click of a Save command button, Form's on error event, or each one individually. Although the error can happen anywhere on the form, if you code correctly and had the right logic, you could display which field it is referencing. I tend to take a lot of things for granted. But, since bph is somewhat of a beginner (I believe that is true and correct me if I am wrong), then they probably would not have this implemented into their app and your suggestion might be a better one for this situation.

But, instead of using:
Code:
If IsNull(Me.Initials) Then
Use the following as it's faster and more efficient:
Code:
If Len(Me.Initials & vbNullString) < 1 Then
Regards,

Beth M
 
Old March 1st, 2004, 02:24 PM
Authorized User
 
Join Date: Jun 2003
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi there,
   I hope I'm not intruding into this thread. Couldn't bph also use the Validation Rule and Validation Text properties. This would create a simple solution without having to write any code at all.

  If you populate the table properties all subsequent forms built using this source will carry those properties forward.

  Validation Rule = Is Not Null
  Validation Text = Please enter your initials.

Thanks,
Mike
 
Old March 1st, 2004, 03:24 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 174
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I usually put the code behind the command button to save. In my error handling I use something similar to the following:
The first two lines go within the dim statements:
Code:
    Const DUPLICATEKEY = 3022
    Const invalid = 2279
Within the code I check to make sure the required fields are complete before continuing the add process like this:
Code:
         If (IsNull(Me![FieldName])) Then
            msg = msg & Me("TXT_FieldName").Caption
            MsgBox msg, , "AppName"
            Cancel = True
            DoCmd.Hourglass False
            Exit Sub
         End If
This is the error handler
Code:
AddError:
    If ERR = DUPLICATEKEY Then
        MsgBox Me("TXT_FIELDNAME").Caption & " must be unique.", , "AppName"
        Me.[FIELDNAME].SetFocus
    ElseIf ERR = invalid Then
        MsgBox "The value you have entered is invalid for this field.  Please enter a valid value.", , "AppName"
    ElseIf ERR = 2465 Or ERR = 3021 Or ERR = 3155 Then
    Else
        MsgBox "Error #" & ERR & ". " & Error$(ERR), , "AppName"
    End If
    DoCmd.Hourglass False
    Exit Sub
The following is my Form_Error event:
Code:
Private Sub Form_Error(DataErr As Integer, Response As Integer)
    Dim db As Database
    Dim dsAlias As Recordset
    Dim sqlstring As String
    Const DUPLICATEKEY = 7786
    Const REFERENTIAL = 3200
    Const invalid = 2279
    Response = DATA_ERRCONTINUE

    If DataErr = DUPLICATEKEY Then
        MsgBox Me("TXT_UniqueField_Label").Caption & " must be unique.", , "AppName"
        Me.[UniqueField].SetFocus
    ElseIf DataErr = invalid Or DataErr = 2113 Then
        MsgBox "The value you have entered is invalid for this field.  Please enter a valid value.", , "AppName"
    ElseIf DataErr = REFERENTIAL Then
        MsgBox "Provide a message about referential integrity that is applicable to your app.", , "AppName"
    ElseIf DataErr = 0 Or DataErr = 2169 Or DataErr = 2473 Then
    ElseIf DataErr = 2237 Then
        MsgBox "The text you entered isn't an item in the list. Select an item from the list, or enter text that matches one of the listed items."
    Else
        MsgBox "DataErr # " & DataErr & ". " & Error$(DataErr), , "AppName"
    End If

End Sub
But you may wish to handle this as Greg suggested, but change the checking to the Len(me.txtFieldname & vbNullString) < 1

Regards,

Beth M
 
Old March 1st, 2004, 03:52 PM
bph bph is offline
Friend of Wrox
 
Join Date: Dec 2003
Posts: 102
Thanks: 2
Thanked 0 Times in 0 Posts
Default

You are correct Beth. I am a beginner. And I appreciate all the help and advice.
I tried the earlier suggestions, which work fine until the user saves the record
and goes to input data for the next record. If I click out of the "initials" box, I get msgbox, then
I'm able go to any control while leaving 'Initials' blank.
I'm going to review all and try again.
Thanks so much to all. bph







Similar Threads
Thread Thread Starter Forum Replies Last Post
Linq and namespaces System and System.Xml roman BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 6 July 4th, 2008 01:15 PM
Urgent.Recover MSMQ messages after system reboot veebhudhi.chandramouli Windows Workflow 0 October 23rd, 2007 01:47 AM
system.stackoverflowexception in system.windows.fo scheidel21 Pro VB.NET 2002/2003 2 May 18th, 2007 12:40 AM
Insert System date and System Time -Form _TextBox cnkumar74 VB How-To 14 February 14th, 2007 10:52 AM
Casting System::Object __gc * to System.Double[] nepsat Visual C++ 3 November 19th, 2005 12:51 PM





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