Set field as required

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have two fields: Qualified and Notes
I would like to make the Notes fields required only if the Qualified field
is set to anything but "Pending" (it can also be Qualified or Disqualified).

Is there a way to set the Notes field to required or not required depending
on the data in another field?

Thanks,
Laura
 
On the before update event of the form you can write the code
Private Sub Form_BeforeUpdate(Cancel As Integer)

If me.Qualified <> "Pending" and (isnull(me.Notes) or me.Notes = "") then
msgbox "Must fill Notes"
me.notes.setfocus
cancel=true
End if
End Sub
 
Yes. In the afterUpdate event of both the QUALIFIED & NOTES field, add a
call to a sub such as

call validateFields

Then create a new sub...

Sub validateFields
If Me.Qualified <> "Pending" then
if len(me.Notes) = 0 then
msgbox("field required")
end if
end if
End sub

Some tweaking might be required.
 
That worked great! Thanks for your help.

Laura

Ofer said:
On the before update event of the form you can write the code
Private Sub Form_BeforeUpdate(Cancel As Integer)

If me.Qualified <> "Pending" and (isnull(me.Notes) or me.Notes = "") then
msgbox "Must fill Notes"
me.notes.setfocus
cancel=true
End if
End Sub
 
I would like to make the Notes fields required only if the Qualified
field is set to anything but "Pending" (it can also be Qualified or
Disqualified).

Set a *table* level validation rule like

Qualified <> "Pending" OR Notes IS NOT NULL

Note: this will protect the data in the table, but is not particularly nice
or helpful to the users. You should use the other approach using the form
BeforeUpdate event in addition to this.

Hope that helps


Tim F
 
Back
Top