Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Apr 2001
    Location
    Joliette, Quebec, Canada
    Posts
    290
    Thanks
    9
    Thanked 0 Times in 0 Posts

    internal validation on form

    On a form I first ask how many servings of fruits did you eat today... Then the number of apples and then the number of oranges. thes i ask about veggies.
    On the before update on the how may veggies did you eat today,I want to check to see if the apples and oranges are greater than the nmuber of fruits. If so I want a message box that says hold-it, the sum of your apples ans oranges is greater than the sum of your fruits! Else go on.

    Private Sub Veggies_BeforeUpdate(Cancel As Integer)
    If (apples + oranges > fruits)
    Then msgBox (Attention you have more apples ans oranges than fruits!,Buttons as vbMsgBoxStyle=vbOkOnly ,Hold it!)
    Else: Veggies.SetFocus
    End If
    End Sub

    <IMG SRC=http://url> <img src=/S/bash.gif border=0 alt=bash width=35 height=39>

  2. #2
    4 Star Lounger
    Join Date
    Dec 2000
    Location
    London, Ontario, Canada
    Posts
    437
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: internal validation on form

    A couple of things, use the OnEnter event and change the code to:
    <hr>Private Sub veggies_Enter()
    If (Apples + Oranges) > fruits Then
    MsgBox "Attention you have more apples and oranges than fruits!", vbOKOnly, "Hold It!"
    Else
    veggies.SetFocus
    End If
    End Sub<hr>

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: internal validation on form

    You don't need the setfocus to veggies if this code is in the OnEnter event of that control. However, you might want to set the focus back to one of the earlier items after you issue the warning to the user.
    Charlotte

Posting Permissions

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