Results 1 to 4 of 4
  1. #1
    ittechguy is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Aug 2015
    Posts
    218

    If statement with multiple or not criteria

    I'm having a hard time getting this code to work here.



    Code:
    inStorage = False
    inStorage = inStorage Or Me.cboEquipmentStatus.Value = 2
    If inStorage _
    Or Not IsNull(Me.cboEquipmentModelNum.Value) Or Not (Me.cboEquipmentModelNum.Value) = "" _
    Or Not IsNull(Me.txtSerialNum.Value) Or Not (Me.txtSerialNum.Value) = "" Then
    'Do stuff here
    End If
    Basically I have If (positive) in storage Or Not (negative) ModelNum Or Not (negative) SerialNum. In the past, I've re-wrote my code to not use "or not" and to just use "or". But it doesn't seem like I can do that for what I need it to do.

    For now I have a msgBox which displays after then. I need the msgBox to display if all three criteria is met. That is,

    Equipment Status is 2
    cboEquipmentModelNum is not null
    txtSerialNum is not null.


    The problem is, I'm getting the msgBox whether value are null or not. What am I doing wrong?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Maybe:

    If inStorage AND Me.cboEquipmentModelNum & "" <> "" AND Me.txtSerialNum & "" <> "" Then
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    ittechguy is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Aug 2015
    Posts
    218
    Thanks for the reply June.

    I'll give that a try in the morning.

    One question tho, a friend of mine who's really good at programming (most every other language bug vba, lol) had told me I need to validate for null and also for empty. So, I've been writing all my code like this because as you know, null and empty is not the same thing.

    But more I work with access, I'm wondering... does it really matter?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    My suggestion will handle validation for null and empty. Because concatenation with Null returns the value of the literal text - in this case conctenating empty string.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 2
    Last Post: 04-02-2015, 12:45 PM
  2. IIF Statement with OR criteria
    By McArthurGDM in forum Queries
    Replies: 8
    Last Post: 03-16-2015, 05:01 PM
  3. If then statement using Yes/No criteria
    By jpiazza in forum Macros
    Replies: 5
    Last Post: 07-12-2014, 11:06 PM
  4. Help with two criteria in an IIF statement.
    By Orozvik in forum Queries
    Replies: 1
    Last Post: 04-26-2013, 02:58 PM
  5. Iif statement with multiple criteria
    By coach32 in forum Queries
    Replies: 1
    Last Post: 09-07-2011, 01:28 AM

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