Mandatory fields in forms

  • Thread starter Thread starter hotplate74
  • Start date Start date
H

hotplate74

Is it possible to make a field in a form mandatory when another field
changes from a default value to anything else?
 
Hotplate,

Use the form's BeforeUpdate event to do this kind of checking:

If Me![FieldWithDefaultValue] <> YourDefaultValue Then
' Use quotes around value if a string literal

If Nz(Me![YourOtherField]) = 0 Then
Cancel = True
Me![YourOtherField].SetFocus
End If

End If

Hope that helps.
Sprinks
 
Sprinks said:
Hotplate,

Use the form's BeforeUpdate event to do this kind of checking:

If Me![FieldWithDefaultValue] <> YourDefaultValue Then
' Use quotes around value if a string literal

If Nz(Me![YourOtherField]) = 0 Then
Cancel = True
Me![YourOtherField].SetFocus
End If

End If

Hope that helps.
Sprinks

Is it possible to make a field in a form mandatory when another field
changes from a default value to anything else?

Thanks
That worked great, how would I create a message with this event, like
"this value is mandatory now?
 
If Me![FieldWithDefaultValue] <> YourDefaultValue Then
' Use quotes around value if a string literal

If Nz(Me![YourOtherField]) = 0 Then
MsgBox "SomeField is required when SomeOtherField equals a
value other than SomeValue" & vbCRLF & "Press OK to enter a value."
' vbCRLF inserts a new line
Cancel = True
Me![YourOtherField].SetFocus
End If

End If




Hotplate,

Use the form's BeforeUpdate event to do this kind of checking:

If Me![FieldWithDefaultValue] <> YourDefaultValue Then
' Use quotes around value if a string literal

If Nz(Me![YourOtherField]) = 0 Then
Cancel = True
Me![YourOtherField].SetFocus
End If

End If

Hope that helps.
Sprinks

Is it possible to make a field in a form mandatory when another field
changes from a default value to anything else?

Thanks
That worked great, how would I create a message with this event, like
"this value is mandatory now?
 
Back
Top