Different fields "Required"

E

Emma Hope

Hi All,

I have a table which is the source for a form, depending on the value
selected in a certain field, i want the user to be required to fill in
certain other fields.

For example

Field1
Field2
Field3
Field4

The user selects 'A' in Field1, they must complete Field2 & Field4 (but not
Field3) OR the user selects 'B' in Field1, they must complete Field3 & Field4
(but not Field2).

I know i can change the 'Required' property on the table but this means all
fields have to be completed. Is there a way on the form itself to change
this, so when the user adds/changes the value of Field1, that certain other
fields become mandatory & others aren't (which i then hide).

Thanks for any help you can give.
Emma
 
M

Marshall Barton

Emma said:
I have a table which is the source for a form, depending on the value
selected in a certain field, i want the user to be required to fill in
certain other fields.

For example

Field1
Field2
Field3
Field4

The user selects 'A' in Field1, they must complete Field2 & Field4 (but not
Field3) OR the user selects 'B' in Field1, they must complete Field3 & Field4
(but not Field2).

I know i can change the 'Required' property on the table but this means all
fields have to be completed. Is there a way on the form itself to change
this, so when the user adds/changes the value of Field1, that certain other
fields become mandatory & others aren't (which i then hide).


You can use table level validation (in the table properties
instead of a field's), I think your rule would be something
like:

(Field1="A" And Field2 Is Not Null And Field4 Is Not Null)
OR (Field1="B" And Field3 Is Not Null And Field4 Is Not
Null)

If that gets too messy or you have several of these
condiditions, an alternative is to use code in the form's
BeforeUpdate event:

If Field1="A" And Not IsNull(Field2) And Not
IsNull(Field4) Then
MsgBox(Pleas supply value for ... )
Cancel = True
ElseIf Field1="B" And Not IsNull(Field2) And Not
IsNull(Field3) Then
MsgBox(Pleas supply value for ... )
Cancel = True
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top