Mandatory fields in forms

H

hotplate74

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

Guest

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
 
H

hotplate74

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?
 
G

Guest

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?
 

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

Similar Threads


Top