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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

make field required only when condition met

Status
Not open for further replies.

FeS2

Technical User
Aug 16, 2002
82
US
I have a simple table that has several fields, and a form for users to enter data on. I want to make it so that when the user selects e-mail from the combo box in fieled1 that the table then makes the date sent field required. Is there a way to do this on the table design because not everyone enters the data by using a form.
 
FeS2,

Simply put, YES! Check out validation rule in the help text. In the table design select your column (field) then look below . On the Validation rule Press F1.

I hope this helps.

Also, look at the example code. (I assume you are using Access 2000.

 
FeS2

Since you can only make a field required or not required, even with the use of multi-field indexes, you have three approaches.

Validation
One approach is through validation coding. Use the BeforeUpdate event procedure. Check to make sure each required field has valid data.

If the validation fails, then cancel the update, and place the cursor / SetFocus on the control that is missing the data.

Second table
The second approach is to use the table design as you requested, but with a twist.

Create a second table for storing your email addresses. Use the primary key from the contact table as the foreign key in the the email table.

Just a though...
tblContact
ContactID - primary key
ContactLN - last name
ContactFN - first name

tblEmail
EmailID - primary key
ContactID - foreign key to tblContact
eMailAdd - text string, required
DateSent - date field, requried

If no email is to be sent, no record is created.

Default value
Again using the BeforeUpdate procedure, set the date field to the current date, or something similar.

Code:
If Not IsDate(Me.YourDateSentField) Then
   Me.YourDateSentField = Date()
End If

Richard
 
Thanks for the replies, I will be trying them out here shortly and see what I get.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top