Results 1 to 4 of 4
  1. #1
    JHarmon is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Feb 2016
    Location
    Tulsa Oklahoma
    Posts
    3

    Testing for multiple conditions help

    Hello,
    I am new here and also new to VBA for Access. I am trying to see if there is a way to test multiple conditions and return "YES" if all come back true and "NO" if any are false. I am trying to compare chemistries and need an exact match. Below is the code that is not working. Any help would be greatly appreciated.

    [Code] Public Function GetInfo()
    On Error GoTo ErrorHandler
    Dim rs As DAO.Recordset
    Dim db As DAO.Database
    Dim strSql As String


    strSql = "SELECT * FROM FunctionQry;"

    Set db = CurrentDb
    Set rs = db.OpenRecordset(strSql)

    rs.MoveLast
    rs.MoveFirst


    Do While Not rs.EOF


    '*****Evaluate Chemistry*****


    If rs!InvC <= rs!StdCMax Then
    If rs!InvMn >= rs!StdMnMin Then
    If rs!InvMn <= rs!StdMnMax Then
    If rs!InvP >= rs!StdPMin Then
    If rs!InvP <= rs!StdPMax Then
    If rs!InvS >= rs!StdSMin Then
    If rs!InvS <= rs!StdSMax Then
    If rs!InvSi >= rs!StdSiMin Then
    If rs!InvSi <= rs!StdSiMax Then

    rs.Edit


    rs!YesNo = "YES"
    rs.Update

    Else
    rs.Edit
    rs!YesNo = "NO"
    rs.Update

    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If


    rs.MoveNext


    Loop

    ErrorHandler:
    Resume Next

    End Function [Code]

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    The short answer is that you'll need ELSE statements on each IF statement.

    Optionally you could do something like creating a total score (1 point for each test) variable and updating the recordset if the total score isn't 9 (the number of checks you are performing)

  3. #3
    JHarmon is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Feb 2016
    Location
    Tulsa Oklahoma
    Posts
    3
    I added the Else at the end of each but it's not exiting when it finds a false. It evaluates the next if and then returns a "YES"

  4. #4
    JHarmon is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Feb 2016
    Location
    Tulsa Oklahoma
    Posts
    3
    I used the count suggestion and it worked. Thanks for the help.

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

Similar Threads

  1. VBA If with multiple conditions
    By Swatskeb in forum Modules
    Replies: 2
    Last Post: 05-22-2014, 04:22 PM
  2. Multiple conditions when building
    By JustAccess in forum Queries
    Replies: 4
    Last Post: 04-29-2013, 12:26 PM
  3. Replies: 3
    Last Post: 08-01-2012, 10:56 AM
  4. Using iif for Multiple Conditions
    By kwilbur in forum Access
    Replies: 5
    Last Post: 12-30-2011, 01:52 PM
  5. Expression with multiple conditions
    By techexpressinc in forum Queries
    Replies: 3
    Last Post: 06-19-2009, 08:33 PM

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