Connecting Tech Pros Worldwide Help | Site Map

Or in the Of clause

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 13th, 2005, 02:04 PM
samotek
Guest
 
Posts: n/a
Default Or in the Of clause

The Or condition in my If clause is not working and seems to give no
results.My target is to achieve a condition by which either quantity or
cartons is null.
That is to say if quantity is Null but cartons is not, the code should
allow the process and not discontinue.
But this doesnt happen. The code i have written looks only for
quantity, and if quantity is null, the message appears, regardless that
i have entered cartons.
Obiisouly my Or in the If condition is not right. Any help ?

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.Quantity) And Me.Parent!customerid <> 123 Or (Me.cartons)
And Me.Parent!customerid <> 123 Then
MsgBox "You must enter either quantity or cartons", vbCritical
Cancel = True
DoCmd.GoToControl "productid"
DoCmd.Beep
DoCmd.Beep
ClearForm
Exit Sub
End If
End Sub


  #2  
Old November 13th, 2005, 02:04 PM
Steve Jorgensen
Guest
 
Posts: n/a
Default Re: Or in the Of clause

I'm not sure why it's not working, but I sure know how to make it more clear,
easier to debug and maintain...

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.Parent!customerid = 123 Then Exit Sub

If IsNull(Me.Quantity) Or Me.Cartons<>False Then
MsgBox "You must enter either quantity or cartons", _
vbCritical+vbOkOnly
Cancel = True
End If

End Sub


On 3 Oct 2005 23:41:05 -0700, "samotek" <samotek@abv.bg> wrote:
[color=blue]
>The Or condition in my If clause is not working and seems to give no
>results.My target is to achieve a condition by which either quantity or
>cartons is null.
>That is to say if quantity is Null but cartons is not, the code should
>allow the process and not discontinue.
>But this doesnt happen. The code i have written looks only for
>quantity, and if quantity is null, the message appears, regardless that
>i have entered cartons.
>Obiisouly my Or in the If condition is not right. Any help ?
>
>Private Sub Form_BeforeUpdate(Cancel As Integer)
>If IsNull(Me.Quantity) And Me.Parent!customerid <> 123 Or (Me.cartons)
>And Me.Parent!customerid <> 123 Then
>MsgBox "You must enter either quantity or cartons", vbCritical
>Cancel = True
>DoCmd.GoToControl "productid"
>DoCmd.Beep
>DoCmd.Beep
>ClearForm
>Exit Sub
>End If
>End Sub[/color]

  #3  
Old November 13th, 2005, 02:04 PM
fredg
Guest
 
Posts: n/a
Default Re: Or in the Of clause

On 3 Oct 2005 23:41:05 -0700, samotek wrote:
[color=blue]
> The Or condition in my If clause is not working and seems to give no
> results.My target is to achieve a condition by which either quantity or
> cartons is null.
> That is to say if quantity is Null but cartons is not, the code should
> allow the process and not discontinue.
> But this doesnt happen. The code i have written looks only for
> quantity, and if quantity is null, the message appears, regardless that
> i have entered cartons.
> Obiisouly my Or in the If condition is not right. Any help ?
>
> Private Sub Form_BeforeUpdate(Cancel As Integer)
> If IsNull(Me.Quantity) And Me.Parent!customerid <> 123 Or (Me.cartons)
> And Me.Parent!customerid <> 123 Then
> MsgBox "You must enter either quantity or cartons", vbCritical
> Cancel = True
> DoCmd.GoToControl "productid"
> DoCmd.Beep
> DoCmd.Beep
> ClearForm
> Exit Sub
> End If
> End Sub[/color]

Your If clause is confusing. Place the associated criteria within
parentheses to make it clearer. Also Me!Cartons should be Me.Cartons =
some criteria. I've made it <1 below. Change it as needed.

If (IsNull(Me.Quantity) And Me.Parent!customerid <> 123) Or
(Me.cartons <1 And Me.Parent!customerid <> 123) Then
etc.

What is ClearForm? I assume some sub procedure.
You do not need the Exit Sub line (unless you have additional code
which you haven't included here).
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
 

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,989 network members.