Results 1 to 2 of 2
  1. #1
    2 Star Lounger
    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?

  2. #2
    Plutonium Lounger
    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
    End If
    End Sub

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts