If And Or Statement Not Working Properly

reberryjr

Well-known Member
Joined
Mar 16, 2017
Messages
701
Office Version
  1. 365
Platform
  1. Windows
Can someone help me figure out why this if statement isn't working properly? The expectation is that if any of the first 5 fields are not null AND one of the first 4 fields are null, it should throw an error. (It is ok for the first 4 fields to be not null, and the 5th field to be null). What's happening is, I'm getting an error even when there's no data in any of the 5 fields.

txt_CTIStart
txt_CTI1stPymt
txt_CTIPymtAmt
cobo_CTIFreq
txt_CTIAmtPaid

Code:
If (Not Len(Me.txt_CTIStart.Value) = 0 Or Not Len(Me.txt_CTI1stPymt.Value) = 0 Or (Me.txt_CTIPymtAmt.Value) > 0 Or Not Len(Me.cobo_CTIFreq.Value) = 0 Or _
    (Me.txt_CTIAmtPaid.Value) > 0) And (Len(Me.txt_CTIStart.Value) = 0 Or Len(Me.txt_CTI1stPymt.Value) = 0 Or Len(Me.txt_CTIPymtAmt.Value) = 0 Or Len(Me.cobo_CTIFreq.Value) = 0) Then
        MsgBox "Please complete the partial information in the CT-I section."
        If Response = vbOK Then Me.txt_CTIStart.SetFocus
Exit Sub
End If
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
So if ive read that right you need all of the textboxes filled except txt_CTIAmtPaid, and also the combobox filled?
 
Last edited:
Upvote 0
Yes, if any of the 5 are not null AND any except for CTIAmtPaid are null, then it should throw the msgbox.
 
Upvote 0
I believe I've fixed it by switching the fields in red font.

Code:
If (Not Len(Me.txt_CTIStart.Value) = 0 Or Not Len(Me.txt_CTI1stPymt.Value) = 0 Or [COLOR=#ff0000]Val(Me.txt_CTIPymtAmt.Text) <> 0 [/COLOR]Or Not Len(Me.cobo_CTIFreq.Value) = 0 Or _
    [COLOR=#ff0000]Val(Me.txt_CTIAmtPaid.Value) <> 0[/COLOR]) And (Len(Me.txt_CTIStart.Value) = 0 Or Len(Me.txt_CTI1stPymt.Value) = 0 Or [COLOR=#ff0000]Val(Me.txt_CTIPymtAmt.Text) = 0 [/COLOR]Or Len(Me.cobo_CTIFreq.Value) = 0) Then
        MsgBox "Please complete the partial information in the CT-I section."
        If Response = vbOK Then Me.txt_CTIStart.SetFocus
Exit Sub
End If
 
Upvote 0

Forum statistics

Threads
1,213,543
Messages
6,114,237
Members
448,555
Latest member
RobertJones1986

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top