Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Making fields required on a form

Status
Not open for further replies.

EllieFant

MIS
May 15, 2001
513
US
I have a form in which I have fields that I want to be required. I have marked them as being required, but when the users of this database use the mouse to click from field to field they are allowed to leave them blank.

I need to find a way that the form (each record) will be checked for all required data before allowing the users to enter a new record. What am I missing?
 
Access checks the required fields before saving the record. If this is OK with you, then you have no problem.

Seaport
 
I have this option set, but the users seem to get past it.

If they use the tab key to move from field to field they can't leave required fields blank, but if they use their mouse to go to fields they want to complete, they are able to leave the required ones blank.

I have this option set on the form. There are some field that are not required depending on the form they are using.

If this don't make sense, let me know and I will try to explain it better. (I am self taught to this point and I haven't learned the correct terms for access)

Thanks so much,
Ellie
 
Ellie
Here's one of many ways. Open the form's property dialog box, then select the BeforeUpdate property, click the ... button and select code builder. This will allow you to write some code that is executed before the recorded is committed. Now you can check the fields to make sure there are data in them prior to saving the record. For instance if you wanted to ensure that the the Last Name field was filled out the code would look something like this.

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull([LastName]) Then
MsgBox "Some message", 0, "Some Title For MsgBox"
End If
End Sub

you can check as many fields as you like. Substitute your field names inside the brackets [AnyFieldName]. If you want to prompt the user for the specific field not updated then use a separate if statement. If you want to have a generic message (i.e. Must fill out record completely) then you can use 1 If statement with Or i.e.
If IsNull([LastName]) Or IsNull([FirstName]) Then
MsgBox "You must enter a last and first Name", 0, "Unable to Save Record"
End If

HTH,
JC
 
Ellie - when you try this out I beleive you will also need the following so that the record doesn't commit if the user doesn't fill out the require data:

If ....
MsgBox ....
Cancel = True
Else
Cancel = False
End If

Sorry
- JC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top