-
Using And with Else If
I have to textboxes that I am attempting to check if they are empty.
If (Len(txtCUSTIDSRCH & "") And Len(txtPNSRCH & "")) = 0 Then
MsgBox "No Search Criteria Entered", vbOKOnly, "No Criteria"
Everything works individually but not using the And. Haven't found much online to resolve.
TIA
-
Try: If Len(txtCUSTIDSRCH & "") = 0 And Len(txtPNSRCH & "") = 0 Then MsgBox "No Search Criteria Entered", vbOKOnly, "No Criteria"
-
or
If Len(txtCUSTIDSRCH & "") + Len(txtPNSRCH & "") = 0 Then....
-
It seems that your first condition isn't a full logical statement.
Condition 1: If (Len(txtCUSTIDSRCH & "") Then....
Condition 2: If Len(txtPNSRCH & "")) = 0 Then....
Add the "= 0" on the end of your first condition and it should work. The second method @Ajax suggested will accomplish the same thing, but compacts both conditions into a single logical argument. It's pretty slick. Instead of checking two if statements, the code just checks one. If either of the lengths are greater than 0 the sum of them will be greater than zero.
-
I prefer readability of code vs. "slick" code if it doesn't hurt performance in each case.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules