Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Jul 2001
    Posts
    280
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Or in the If clause (Access 2000)

    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. #2
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Or in the If clause (Access 2000)

    What type of field is cartons? Are you testing whether it is true, or whether it is null? (Have you left out an IsNUll?)

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


    The other thing to help sort out the logic is to put in brackets

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



  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Or in the If clause (Access 2000)

    Try

    If (IsNull(Me.Quantity) Or IsNull(Me.Cartons)) And Me.Parent!CustomerID <> 123 Then

    Note the extra pair of parentheses around IsNull(Me.Quantity) Or IsNull(Me.Cartons). Without brackets, And has precedence above Or. The brackets force the Or to be evaluated before the And here.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •