Connecting Tech Pros Worldwide Help | Site Map

VBA Code for Is Not

 
LinkBack Thread Tools Search this Thread
  #1  
Old March 14th, 2008, 07:45 PM
WPW07
Guest
 
Posts: n/a
Default 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_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



  #2  
Old March 14th, 2008, 07:45 PM
paii, Ron
Guest
 
Posts: n/a
Default 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")


  #3  
Old March 14th, 2008, 07:55 PM
Guillermo_Lopez
Guest
 
Posts: n/a
Default 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
  #4  
Old March 14th, 2008, 07:55 PM
WPW07
Guest
 
Posts: n/a
Default 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!
  #5  
Old March 14th, 2008, 08:05 PM
Salad
Guest
 
Posts: n/a
Default 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
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.