VBA Code for Is Not

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • WPW07

    VBA Code for Is Not

    Hello,

    I'm trying to add some data validation to the BeforeUpdate event of a
    form. I want the user to select a number between 1 and 3 for the
    [Choice] field. Can I use something like IsNot? Sorry, a little
    rusty here!

    Thanks

    =============== ======

    Private Sub Form_BeforeUpda te(Cancel As Integer)
    'Data validation to ensure a choice number between 1 and 3 is
    selected.
    If IsNot (Me.Choice (>=1 And <=3) Then
    MsgBox "Please select a choice number between 1 and 3.."
    DoCmd.CancelEve nt
    Me.Choice.SetFo cus
    End If


  • paii, Ron

    #2
    Re: VBA Code for Is Not


    "WPW07" <wwisnieski@gma il.comwrote in message
    news:547f7eb1-f441-42bb-b104-1023dc4a9456@8g 2000hse.googleg roups.com...
    Hello,
    >
    I'm trying to add some data validation to the BeforeUpdate event of a
    form. I want the user to select a number between 1 and 3 for the
    [Choice] field. Can I use something like IsNot? Sorry, a little
    rusty here!
    >
    Thanks
    >
    =============== ======
    >
    Private Sub Form_BeforeUpda te(Cancel As Integer)
    'Data validation to ensure a choice number between 1 and 3 is
    selected.
    If IsNot (Me.Choice (>=1 And <=3) Then
    MsgBox "Please select a choice number between 1 and 3.."
    DoCmd.CancelEve nt
    Me.Choice.SetFo cus
    End If
    >
    >
    Replace IsNot with Not

    iif(not (True),"Not False","Not True")


    Comment

    • Guillermo_Lopez

      #3
      Re: VBA Code for Is Not

      On Mar 14, 3:39 pm, "paii, Ron" <n...@no.comwro te:
      "WPW07" <wwisnie...@gma il.comwrote in message
      >
      news:547f7eb1-f441-42bb-b104-1023dc4a9456@8g 2000hse.googleg roups.com...
      >
      >
      >
      >
      >
      Hello,
      >
      I'm trying to add some data validation to the BeforeUpdate event of a
      form.  I want the user to select a number between 1 and 3 for the
      [Choice] field.   Can I use something like IsNot?  Sorry, a little
      rusty here!
      >
      Thanks
      >
      =============== ======
      >
      Private Sub Form_BeforeUpda te(Cancel As Integer)
      'Data validation to ensure a choice number between 1 and 3 is
      selected.
        If IsNot (Me.Choice (>=1 And <=3) Then
               MsgBox "Please select a choice number between 1 and 3..."
               DoCmd.CancelEve nt
               Me.Choice.SetFo cus
       End If
      >
      Replace IsNot with Not
      >
       iif(not (True),"Not False","Not True")- Hide quoted text -
      >
      - Show quoted text -
      Why not use Me.Choice as a combo Box. Make it so that you cant type
      anything there in KeyPress method : AcsiiCode = 0. And have the
      options available obviosly having a default option.

      - GL

      Comment

      • WPW07

        #4
        Re: VBA Code for Is Not

        On Mar 14, 3:49 pm, Guillermo_Lopez <g.lo...@iesdr. comwrote:
        On Mar 14, 3:39 pm, "paii, Ron" <n...@no.comwro te:
        >
        >
        >
        "WPW07" <wwisnie...@gma il.comwrote in message
        >
        news:547f7eb1-f441-42bb-b104-1023dc4a9456@8g 2000hse.googleg roups.com...
        >
        Hello,
        >
        I'm trying to add some data validation to the BeforeUpdate event of a
        form. I want the user to select a number between 1 and 3 for the
        [Choice] field. Can I use something like IsNot? Sorry, a little
        rusty here!
        >
        Thanks
        >
        =============== ======
        >
        Private Sub Form_BeforeUpda te(Cancel As Integer)
        'Data validation to ensure a choice number between 1 and 3 is
        selected.
        If IsNot (Me.Choice (>=1 And <=3) Then
        MsgBox "Please select a choice number between 1 and 3.."
        DoCmd.CancelEve nt
        Me.Choice.SetFo cus
        End If
        >
        Replace IsNot with Not
        >
        iif(not (True),"Not False","Not True")- Hide quoted text -
        >
        - Show quoted text -
        >
        Why not use Me.Choice as a combo Box. Make it so that you cant type
        anything there in KeyPress method : AcsiiCode = 0. And have the
        options available obviosly having a default option.
        >
        - GL
        Whoa, forgot about limit to list in a combo box. I'll use that.
        Thanks for your help!

        Comment

        • Salad

          #5
          Re: VBA Code for Is Not

          WPW07 wrote:
          Hello,
          >
          I'm trying to add some data validation to the BeforeUpdate event of a
          form. I want the user to select a number between 1 and 3 for the
          [Choice] field. Can I use something like IsNot? Sorry, a little
          rusty here!
          >
          Thanks
          >
          =============== ======
          >
          Private Sub Form_BeforeUpda te(Cancel As Integer)
          'Data validation to ensure a choice number between 1 and 3 is
          selected.
          If IsNot (Me.Choice (>=1 And <=3) Then
          MsgBox "Please select a choice number between 1 and 3.."
          DoCmd.CancelEve nt
          Me.Choice.SetFo cus
          End If
          >
          Not that I know off.
          If (Me.Choice <1 Or Me.Choice >3) then
          or
          If Instr("123",Me. Choice) = 0 then
          would work.

          BTW, most folks would use
          Cancel = True
          instead of
          DoCmd.CancelEve nt

          Naike

          Comment

          Working...