Results 1 to 7 of 7
  1. #1
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    Making a field required in code (2002)

    Hi!

    I am looking for code to make a field required. I know how to set this in a table, however I don't need it to be required at all times. Only if certain criteria are met. I can set the criteria in if/than statements but wasn't sure how to set the code for the field. IE

    If me.DateDue = somedate then
    me.Month .............................is required.

    Thanks,
    Leesha

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

    Re: Making a field required in code (2002)

    Is "somedate" a fixed date, or is it the value of another field or the result of a calculation?

  3. #3
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Making a field required in code (2002)

    It is a value of another field.

  4. #4
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Making a field required in code (2002)

    In your form's BeforeUpdate event, you need to put code that checks for the conditions you want. Something like this:

    if Me.DateDue = somedate then
    If isnull(Me.Month) then
    MsgBox "You must make an entry in the Month field!",vbcritical
    Cancel=True
    Exit Sub
    End If
    End If
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  5. #5
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Making a field required in code (2002)

    Thanks! I'll give it a shot!

    Leesha

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

    Re: Making a field required in code (2002)

    If DueDate, SomeDate and Month are all in the same table, you could set a Validation Rule in the table properties:

    Not ([DueDate]=[SomeDate] And [Month] Is Null)

    Enter an appropriate warning in the table's Validation Text property.

    Mark's suggestion of a Before Update event for the form may be more user-friendly.

  7. #7
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Making a field required in code (2002)

    Thanks Hans, I'll try both. It's another new learning area so it will give me some practice!

    Leesha

Posting Permissions

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