Required text and error messages

Buckethead

New member
Local time
Today, 19:43
Joined
Apr 10, 2012
Messages
4
Hi there

I want to validate a text field, and its a required field, how do I validate the text with a message such as "You need to enter a first name in his field"? What characters or text string d I need to put in the 'Validation Rule' field and can I put in the validation text field the error message that I mentioned above?
Being a required text will a default error message override the error message I have above?

Im a newbie on Access and although I have several books on Access, sometimes I still feel the need to ask a question. I do apologize if this is really basic stuff.

Cheers
Glenn.
 
If you want you can use the Default message provided by access, this can be accomplished by explicitly mentioning in the table that the field cannot be null (in the Validation rule use 'Is Not Null') and the text can be "You need to enter a first name in his field"...

Else if you use a Form to update the records, then on the Text Field's 'After Update' property or 'On Lost Focus' property can be coded as follows to achieve it.. REMEBER THIS IS CREATING A CUSTOM MESSAGE..

Code:
Private Sub your_text_field_name_AfterUpdate()
    If Len(your_text_field_name.Value&"")=0 Then
        MsgBox ("You need to enter a first name in his field")
        your_text_field_name.SetFocus
    End If
End Sub
Follow either of the two methods..
 
Last edited:
When dealing with "basic stuff" the best thing to do is to try, according to your understanding. Look up the property in the documentation (press F1 when the curoser is in that property field), google.. and try. See what Access does, or what messages it gives you.

In this way you'll get the terminology, and learn to use the documentation, and to understand it.
 
if you don't enter anything in the first name (say) then the events for that control will not fire

you then have two choices

a) set the field as required, allow zero length = false - then access will reject the record (when the whole record is savef), but with an not-so-friendly message - note that there could be other errors also, preventing saving)

b) use the FORMS before update event to test such fields, and reject the record - this event happens BEFORE the above event, so you never see the above message

c) in interests of completeness, you could interecept the first error, with the on error event, and replace the access message with your own. personally, i would use option b)
 

Users who are viewing this thread

Back
Top Bottom