Results 1 to 7 of 7
  1. #1
    Join Date
    May 2004
    Posts
    80

    Unanswered: How to set validation rule to only even numbers?

    I need to set a validation rule or condition that only allows even numbers to be entered into that field, as well as prohibiting values that are greater than 12. Any suggestions? Thank you.

    - Grace
    Last edited by graceadair; 05-14-04 at 05:48.

  2. #2
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    Use the MOD Function

  3. #3
    Join Date
    Jul 2003
    Posts
    73
    I'd put the following in the BeforeUpdate event of the TextBox:

    Code:
    Private Sub TextBoxWhatever_BeforeUpdate(Cancel As Integer)
    On Error Goto ConvertError
    
    Dim intTemp as Integer
    
        intTemp = CInt(TextBoxWhatever.Text)
    
        If intTemp Mod 2 = 1 or intTemp > 12 Then
            MsgBox "Cannot have uneven or values greater than 12"
            Cancel = True
        End If
    
    ExitSub:
        Exit Sub
    
    ConvertError:
        MsgBox "Cannot have uneven or values greater than 12"
        Cancel = True
        Resume ExitSub
    End Sub

  4. #4
    Join Date
    May 2004
    Posts
    80

    Thankyou

    Thanks very much for your reply - it sounds great, will definitely try it.

    You guys out there are amazing with what you know!!!

    - Grace

  5. #5
    Join Date
    May 2004
    Posts
    80

    Actually...where do I put it?

    Sorry, I thought I knew what I needed to do with the code, but I realise now that I don't. Can you tell me the steps I need to take to get there? I tried inserting it in the Control Source section of the Capacity textbox, but it didn't do anything.

    Also, how much of the following do I replace with the name of my textbox (in this case, Capacity?)

    "TextBoxWhatever_BeforeUpdate"

    Thanks

    - Grace

  6. #6
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1

    Lightbulb

    Put your Cursor in the required Filed, right mouse/Properties/events then search the BeforeUpdate event press the three points and write your code there

  7. #7
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    You have to chane the TextBoxWhatever into Capacity if your TextBox is called Capacity

Posting Permissions

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