Results 1 to 2 of 2
2005-07-14, 10:59 #1
- Join Date
- May 2002
- Bristol, Avon, England
- Thanked 0 Times in 0 Posts
One or other field must be complete (2000)
What is the best way to ensure that one or other (or both) of two fields must be completed on a form?
2005-07-14, 11:07 #2
- Join Date
- Mar 2002
- Thanked 28 Times in 28 Posts
Re: One or other field must be complete (2000)
You can use code in the Before Update event of the form. Let's say you have text boxes txtField1 and txtField2.
Private Sub form_BeforeUpdateEvent(Cancel As Integer)
If IsNull(Me.txtField1) And IsNull(Me.txtField2) Then
' Inform the user
MsgBox "You must complete Field1 or Field2 (or both).", vbExclamation
' Set focus to one of the text boxes that must be completed
' Cancel the update
Cancel = True
If both text boxes are bound to fields in the underlying table, you can use a Validation Rule at the table level instead:
- Open the table in design view.
- Activate the Properties window.
- Enter the following in the Validation Rule property (substitute the correct field names):
Not (IsNull([Field1]) And IsNull([Field2]))
- Enter an appropriate error message in the Validation Text property.