 |
| 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
|
|
|
|

March 1st, 2004, 10:54 AM
|
|
Friend of Wrox
|
|
Join Date: Dec 2003
Posts: 102
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
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
|
|

March 1st, 2004, 12:20 PM
|
|
Authorized User
|
|
Join Date: Dec 2003
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

March 1st, 2004, 12:37 PM
|
|
Friend of Wrox
|
|
Join Date: Dec 2003
Posts: 102
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
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
|
|

March 1st, 2004, 01:11 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 174
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

March 1st, 2004, 01:52 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
|
|
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
|
|

March 1st, 2004, 02:00 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 174
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

March 1st, 2004, 02:24 PM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

March 1st, 2004, 03:24 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 174
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

March 1st, 2004, 03:52 PM
|
|
Friend of Wrox
|
|
Join Date: Dec 2003
Posts: 102
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
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
|
|
 |