Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Jun 2005
    Location
    Atlanta, Georgia, USA
    Posts
    208
    Thanks
    0
    Thanked 0 Times in 0 Posts

    linking 2 fields (2000)

    I have 2 fields: a yes or no check box and a date field. I want to make it where if the box is checked yes then I want to make it where they have to fill in the date before exiting the record. How would this be possible?

    benji

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: linking 2 fields (2000)

    One possibility is to set a Validation Rule at the table level:
    <UL><LI>Open the table in design view.
    <LI>Activate the Properties window.
    <LI>Enter a Validation Rule:

    [YesnoField]=False Or [DateField] Is Not Null

    <LI>Enter an appropriate warning in the Validation Text property, e.g.

    You must enter a date!

    <LI>Save the table design.[/list]Another possibility is to use the Before Update event of a form bound to the table.
    <UL><LI>Open the form in design view.
    <LI>Activate the Event tab of the Properties window.
    <LI>Click in the Before Update event.
    <LI>Select [Event Procedure] from the dropdown list.
    <LI>Click the ... to the right of the dropdown arrow.
    <LI>Make the code look like this:

    Private Sub Form_BeforeUpdate(Cancel As Integer)
    If Me.YesNoField = True And IsNull(Me.DateField) Then
    MsgBox "You must enter a date.", vbExclamation
    Me.DateField.SetFocus
    Cancel = True
    End If
    End Sub

    <LI>Switch back to Access and save the form.[/list]In both cases, you must substitute the appropriate names for YesNoField and DateField.

  3. #3
    2 Star Lounger
    Join Date
    Jun 2005
    Location
    Atlanta, Georgia, USA
    Posts
    208
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: linking 2 fields (2000)

    Thanks works perfectly. You are a genius.

  4. #4
    2 Star Lounger
    Join Date
    Jun 2005
    Location
    Atlanta, Georgia, USA
    Posts
    208
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: linking 2 fields (2000)

    This is an old followup. What if there are now 3 fields that are required if the yes/no box is checked. I am not sure how this validation is working for I used your first example.

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: linking 2 fields (2000)

    The validation rule should look like this:

    [YesnoField]=False Or ([Field1] Is Not Null And [Field2] Is Not Null And [Field3] Is Not Null)

    You must, of course, substitute the correct field names and modify the validation message accordingly. However, I would prefer the form-based solution - table-based validation rules quickly become unwieldy, and you only have one validation message. Using VBA code behind a form allows you to display a customized message for each individual field.

Posting Permissions

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