A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

required field



 
 
Thread Tools Display Modes
  #1  
Old July 31st, 2008, 02:29 AM posted to microsoft.public.access.forms
timbits35 via AccessMonster.com
external usenet poster
 
Posts: 20
Default required field

Hi,

I have read through many pages of how to handle required fields and still
have a question. The majority of answers state that the best way to handle
this is by using the form's Before Update property. Which is fine and I have
tried and it works. But I want the error message to come up before the user
leaves the field, not have to wait until the form is saved. So I tried using
the On Exit property and it works too. But then I read comments that maybe
the user will not enter the field in the first place. So how do I force the
user to enter each field which I choose to be required? If I open the form
and set the focus to the first required field and use the code below is it ok?
Should I stick with validiting the control property using On Exit, Before
Update, On Lost Focus...which is the best?

If IsNull(Me.[lname]) Then
MsgBox "You must enter the name"
Me!lname.SetFocus
Cancel = True
End If

Thank you,
Liane

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/200807/1

  #2  
Old July 31st, 2008, 03:13 AM posted to microsoft.public.access.forms
Allen Browne
external usenet poster
 
Posts: 11,706
Default required field

The best way requires no code at all.

Open the table in design view.
Select the field.
In the lower pane of table design, set Required to Yes.

Now if you try to save a record without a value in this field (even if you
never visited it), Access won't let you.

If you wanted a custom message, set these properties for the field in table
design:
Required No
Validation Rule Is Not Null
Validation Text "You did what???"

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"timbits35 via AccessMonster.com" u34694@uwe wrote in message
news:87f270245d5e0@uwe...

I have read through many pages of how to handle required fields and still
have a question. The majority of answers state that the best way to handle
this is by using the form's Before Update property. Which is fine and I
have
tried and it works. But I want the error message to come up before the
user
leaves the field, not have to wait until the form is saved. So I tried
using
the On Exit property and it works too. But then I read comments that maybe
the user will not enter the field in the first place. So how do I force
the
user to enter each field which I choose to be required? If I open the form
and set the focus to the first required field and use the code below is it
ok?
Should I stick with validiting the control property using On Exit, Before
Update, On Lost Focus...which is the best?

If IsNull(Me.[lname]) Then
MsgBox "You must enter the name"
Me!lname.SetFocus
Cancel = True
End If

Thank you,
Liane


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 11:36 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.