By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,326 Members | 1,938 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,326 IT Pros & Developers. It's quick & easy.

Help with error messages in access

P: 2
Hi i am creating a database for a college Military Science department and have it just about done. I am encountering some issues with the debug phase. I need some error messages that are user friendly.

For instance:

I have a form that cadets will fill out. Information such as name, unit name, grade level, gpa, ect. ect.

When the teachers enter this into the database through the cadet form I want friendly error messages to appear if there is an empty field. Either when a save button is clicked or the text box loses focus. I have tried using the error codes (3314, ect.) but the code window will not return a code when I click save and an empty field is present, i do get the standard message. It does return the 3314 code when I click the "x" to close the form.

Any ideas?
Dec 11 '07 #1
Share this Question
Share on Google+
4 Replies


ADezii
Expert 5K+
P: 8,669
Hi i am creating a database for a college Military Science department and have it just about done. I am encountering some issues with the debug phase. I need some error messages that are user friendly.

For instance:

I have a form that cadets will fill out. Information such as name, unit name, grade level, gpa, ect. ect.

When the teachers enter this into the database through the cadet form I want friendly error messages to appear if there is an empty field. Either when a save button is clicked or the text box loses focus. I have tried using the error codes (3314, ect.) but the code window will not return a code when I click save and an empty field is present, i do get the standard message. It does return the 3314 code when I click the "x" to close the form.

Any ideas?
Place similar code to what I am showing you in the BeforeUpdate() Event of the Form, this way the Field Validation will be centralized, and regardless of which mechanism you may use to Save the Form, the Event will be fired and the Record will not be Saved until all Required Fields contain data.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2. If IsNull(Me![Field1]) Then
  3.   MsgBox "You must enter a value in <Your Field Name>", vbExclamation, "Missing Entry"
  4.     Cancel = True: Me![Field1].SetFocus
  5. ElseIf IsNull(Me![Field2]) Then
  6.   MsgBox "You must enter a value in <Your Field Name>", vbExclamation, "Missing Entry"
  7.     Cancel = True: Me![Field2].SetFocus
  8. End If
  9. End Sub
Dec 11 '07 #2

P: 2
Place similar code to what I am showing you in the BeforeUpdate() Event of the Form, this way the Field Validation will be centralized, and regardless of which mechanism you may use to Save the Form, the Event will be fired and the Record will not be Saved until all Required Fields contain data.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2. If IsNull(Me![Field1]) Then
  3.   MsgBox "You must enter a value in <Your Field Name>", vbExclamation, "Missing Entry"
  4.     Cancel = True: Me![Field1].SetFocus
  5. ElseIf IsNull(Me![Field2]) Then
  6.   MsgBox "You must enter a value in <Your Field Name>", vbExclamation, "Missing Entry"
  7.     Cancel = True: Me![Field2].SetFocus
  8. End If
  9. End Sub
Alright. Now if I have 13 fields in the form would I just continue through to "field13"?
Dec 11 '07 #3

missinglinq
Expert 2.5K+
P: 3,532
You could or you could loop thru the controls a variety of ways. Here's one example. It requires that you goto Properties - Other and enter a question mark (no quotation marks) in the Tag Property of each control you want to check. You can do this in one fell swopr by selecting all of the controls and changing the Tag property enmasse as it were.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2. Dim Msg As String, Style As Integer, Title As String
  3.    Dim DL As String, ctl As Control
  4.  
  5.    DL = vbNewLine & vbNewLine
  6.  
  7.    For Each ctl In Me.Controls
  8.  
  9.      If ctl.Tag = "?" Then
  10.        If Trim(ctl.Value & "") = "" Then
  11.  
  12.         Msg = "'" & ctl.Name & "' is Required!" & DL & _
  13.                "Please enter a value or hit Esc to abort the record . . ."
  14.          Style = vbInformation + vbOKOnly
  15.          Title = "Required Data Missing! . . ."
  16.          MsgBox Msg, Style, Title
  17.          ctl.SetFocus
  18.          Cancel = True
  19.          Exit For
  20.          End If
  21.       End If
  22.    Next
  23. End Sub
  24.  
Welcome to TheScripts!

Linq ;0)>
Dec 11 '07 #4

ADezii
Expert 5K+
P: 8,669
Alright. Now if I have 13 fields in the form would I just continue through to "field13"?
Another option is to set the Required Property of these 13 Fields in the Table to Yes. If the Required Property is set to Yes, when you enter data in a Record, you must enter a value in the field or in any control bound to the field, and the value cannot be Null.
Dec 11 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.