Results 1 to 5 of 5
  1. #1
    dweekley is offline Advanced Beginner
    Windows XP Access 2002 (version 10.0)
    Join Date
    May 2010
    Posts
    52

    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

  2. #2
    jwhite is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Dec 2012
    Location
    North Carolina
    Posts
    349
    Try: If Len(txtCUSTIDSRCH & "") = 0 And Len(txtPNSRCH & "") = 0 Then MsgBox "No Search Criteria Entered", vbOKOnly, "No Criteria"



  3. #3
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,845
    or

    If Len(txtCUSTIDSRCH & "") + Len(txtPNSRCH & "") = 0 Then....

  4. #4
    ohmydatabase's Avatar
    ohmydatabase is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Feb 2017
    Posts
    79
    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.

  5. #5
    jwhite is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Dec 2012
    Location
    North Carolina
    Posts
    349
    I prefer readability of code vs. "slick" code if it doesn't hurt performance in each case.

Please reply to this thread with any new information or opinions.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums