Connecting Tech Pros Worldwide Help | Site Map

Or in the Of clause

samotek
Guest
 
Posts: n/a
#1: Nov 13 '05
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

Steve Jorgensen
Guest
 
Posts: n/a
#2: Nov 13 '05

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]

fredg
Guest
 
Posts: n/a
#3: Nov 13 '05

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
Closed Thread