Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms / July 2008

Tip: Looking for answers? Try searching our database.

required field

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
timbits35 - 31 Jul 2008 02:28 GMT
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
Allen Browne - 31 Jul 2008 03:13 GMT
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???"

Signature

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.

> 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
[quoted text clipped - 21 lines]
> Thank you,
> Liane
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.