Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Or in the If clause

samoteksamotek Member Posts: 9
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

Comments

  • aatkbdaatkbd Member Posts: 42
    Add some parentheses to your if statement and it should work.

    : 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 [b][red]([/red][/b]IsNull(Me.Quantity) And Me.Parent!customerid <> 123[b][red])[/red][/b] Or [b][red]([/red][/b]Me.cartons And Me.Parent!customerid <> 123[b][red])[/red][/b] 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
    :
    :

Sign In or Register to comment.