Connecting Tech Pros Worldwide Help | Site Map

VBA Code for Is Not

WPW07
Guest
 
Posts: n/a
#1: Mar 14 '08
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_BeforeUpdate(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.CancelEvent
Me.Choice.SetFocus
End If


paii, Ron
Guest
 
Posts: n/a
#2: Mar 14 '08

re: VBA Code for Is Not



"WPW07" <wwisnieski@gmail.comwrote in message
news:547f7eb1-f441-42bb-b104-1023dc4a9456@8g2000hse.googlegroups.com...
Quote:
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_BeforeUpdate(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.CancelEvent
Me.Choice.SetFocus
End If
>
>
Replace IsNot with Not

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


Guillermo_Lopez
Guest
 
Posts: n/a
#3: Mar 14 '08

re: VBA Code for Is Not


On Mar 14, 3:39*pm, "paii, Ron" <n...@no.comwrote:
Quote:
"WPW07" <wwisnie...@gmail.comwrote in message
>
news:547f7eb1-f441-42bb-b104-1023dc4a9456@8g2000hse.googlegroups.com...
>
>
>
>
>
Quote:
Hello,
>
Quote:
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!
>
Quote:
Thanks
>
Quote:
=====================
>
Quote:
Private Sub Form_BeforeUpdate(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.CancelEvent
* * * * *Me.Choice.SetFocus
*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
WPW07
Guest
 
Posts: n/a
#4: Mar 14 '08

re: VBA Code for Is Not


On Mar 14, 3:49 pm, Guillermo_Lopez <g.lo...@iesdr.comwrote:
Quote:
On Mar 14, 3:39 pm, "paii, Ron" <n...@no.comwrote:
>
>
>
Quote:
"WPW07" <wwisnie...@gmail.comwrote in message
>
Quote:
news:547f7eb1-f441-42bb-b104-1023dc4a9456@8g2000hse.googlegroups.com...
>
Quote:
Quote:
Hello,
>
Quote:
Quote:
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!
>
Quote:
Quote:
Thanks
>
Quote:
Quote:
=====================
>
Quote:
Quote:
Private Sub Form_BeforeUpdate(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.CancelEvent
Me.Choice.SetFocus
End If
>
Quote:
Replace IsNot with Not
>
Quote:
iif(not (True),"Not False","Not True")- Hide quoted text -
>
Quote:
- 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!
Salad
Guest
 
Posts: n/a
#5: Mar 14 '08

re: VBA Code for Is Not


WPW07 wrote:
Quote:
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_BeforeUpdate(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.CancelEvent
Me.Choice.SetFocus
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.CancelEvent

Naike
http://www.youtube.com/watch?v=0VmhcBbfsp0
Closed Thread