Require fields

J

Jessica

I have a field call p structure which is a dropdown and one call p revised
date. When some one makes a selection on the p structure field i would like
the p revised date field to be a require field. How can i do it?
 
B

Beetle

Assuming you are using a form for data entry (you should be)
and not working directly in the table (you shouldn't be),
you would use code like the following in the Before Update
event of the form (substitute your actual control names);

Private Sub Form_BeforeUpdate(Cancel As Integer)

If Not IsNull(Me![p structure]) Then
If IsNull(Me![p revised]) Then
MsgBox "Please enter a Revised Date"
Cancel = True
End If
End If

End Sub
 
A

Arvin Meyer MVP

In a form (it cannot be done in a table) a bit of code something like
(untested)

Private Sub p_structure_AfterUpdate()
If Len(Me.[p structure] & vbNullString) > 0 Then
MsgBox "You must fill in p revised date", vbOKOnly, "Required"
Me.[p revised date].SetFocus
End If
End Sub

and then:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Len(Me.[p structure] & vbNullString) > 0 and If Len(Me.[p revised
date] & vbNullString) = 0 Then
MsgBox "The date in p revised date is REQUIRED"
Cancel = True
End If
End Sub

Now they must either delete the data in p structure or add the data in p
revised date.
 
C

Clifford Bass

Hi Jessica,

If you want to do it in the table you could use the table-level
Validation Rule property (right-click the table window while in design mode
and choose Properties). Set it to:

(IsNull([p structure]) And IsNull([p revised])) Or (Not IsNull([p
structure]) And Not IsNull([p revised]))

This assumes that if [p structure] is null [p revised] should be null
also. If that is not the case and you allow [p structure] to be null while
[p revised] is not null then use:

IsNull([p structure]) Or (Not IsNull([p structure]) And Not IsNull([p
revised]))

You can use the Validation Text property to provide a meaningful message.

Clifford Bass
 
J

Jessica

if i already have the below for another field can i have two event procedures?

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Not IsNull(Me![Closing Date]) Then
If Nz(Me![Exit Reason], "") = "" Then
MsgBox " You must choose an exit reason"
Cancel = True
Me![Exit Reason].SetFocus
End If
End If
End Sub


Beetle said:
Assuming you are using a form for data entry (you should be)
and not working directly in the table (you shouldn't be),
you would use code like the following in the Before Update
event of the form (substitute your actual control names);

Private Sub Form_BeforeUpdate(Cancel As Integer)

If Not IsNull(Me![p structure]) Then
If IsNull(Me![p revised]) Then
MsgBox "Please enter a Revised Date"
Cancel = True
End If
End If

End Sub

--
_________

Sean Bailey


Jessica said:
I have a field call p structure which is a dropdown and one call p revised
date. When some one makes a selection on the p structure field i would like
the p revised date field to be a require field. How can i do it?
 
J

John W. Vinson

if i already have the below for another field can i have two event procedures?

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Not IsNull(Me![Closing Date]) Then
If Nz(Me![Exit Reason], "") = "" Then
MsgBox " You must choose an exit reason"
Cancel = True
Me![Exit Reason].SetFocus
End If
End If
End Sub

The Form can have only one BeforeUpdate event, but that event can check any
number of controls.
 

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