Results 1 to 12 of 12
  1. #1
    royalrochelle is offline Novice
    Windows XP Access 2007
    Join Date
    May 2010
    Posts
    13

    Multiple IF-Then-Else Statement...PLEASE HELP

    Can someone please guide me in the right direction with this problem that I am having? I am working on a multiple IF-Then-Else statement but I can’t seem to get it to work properly. Here are three different If-Then-Else statements that I have tried:
    Example 1:
    If Me.txtEliAge > "18" Then
    Me.txtDemEligible = "Yes"
    Else


    Me.txtDemEligible = "No"
    End If

    If Me.txtEliLiving <> "3" Then
    Me.txtDemEligible = "Yes"
    Else
    Me.txtDemEligible = "No"
    End If

    If Me.txtEliERReason <> “2” then
    Me.txtDemEligible = “Yes”
    Else
    Me.txtDemEligible = “No”
    End If


    Example 2:
    If Me.txtEliAge > "18" or Me.txtEliLiving <> "3 or Me.txtEliERReason <> “2” Then
    Me.txtDemEligible = "Yes"
    Else
    Me.txtDemEligible = "No"
    End If

    Example 3:
    If Me.txtEliAge > "18" Then

    If Me.txtEliLiving <> "3" Then
    If Me.txtEliERReason <> “2” then
    Me.txtDemEligible = "Yes"
    Else
    Me.txtDemEligible = "No"
    End If
    End If
    End If


    The 1st and 3rd example seemed to work the best but once I added the third If which is “If me.txtEliERReason <> “2” then”, it doesn’t give me the result I am looking for. What am I doing wrong?

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Example 2 seems ok if you add the "
    Example 2:
    If Me.txtEliAge > "18" or Me.txtEliLiving <> "3" or Me.txtEliERReason <> “2” Then
    Me.txtDemEligible = "Yes"
    Else
    Me.txtDemEligible = "No"
    End If

  3. #3
    royalrochelle is offline Novice
    Windows XP Access 2007
    Join Date
    May 2010
    Posts
    13
    Thanks for pointing that out Orange and a big thank you for your fast reply. I do have that for the code but I just forgot to add that here. Sorry about that but even with the proper quotation marks I still get the same problem

  4. #4
    dreday's Avatar
    dreday is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    58
    You might want to try adding some parenthesis just to keep things straight -

    Example 2:
    If ((Me.txtEliAge > "18") or (Me.txtEliLiving <> "3") or (Me.txtEliERReason <> “2”))
    Then
    Me.txtDemEligible = "Yes"
    Else
    Me.txtDemEligible = "No"
    End If


  5. #5
    royalrochelle is offline Novice
    Windows XP Access 2007
    Join Date
    May 2010
    Posts
    13
    Thanks dreday! I just tried it but it does not work. For some reason it doesn't even recognize the word Or which is really frustrating me.

  6. #6
    dreday's Avatar
    dreday is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    58
    Hmmmm, very odd. Can you post a screenshot of the if/then statement in your VBA code? Maybe that will have some extra info in it.

  7. #7
    royalrochelle is offline Novice
    Windows XP Access 2007
    Join Date
    May 2010
    Posts
    13
    [IMG]file:///C:/DOCUME%7E1/sw337/LOCALS%7E1/Temp/moz-screenshot.png[/IMG][/IMG]

    I hope this works. Its the one that starts with Private Sub cmdOpenRelationships_Click()

  8. #8
    royalrochelle is offline Novice
    Windows XP Access 2007
    Join Date
    May 2010
    Posts
    13
    Shoot! It didn't work. I will try again

  9. #9
    royalrochelle is offline Novice
    Windows XP Access 2007
    Join Date
    May 2010
    Posts
    13



    Its the one that starts with Its the one that starts with Private Sub cmdOpenRelationships_Click()

  10. #10
    dreday's Avatar
    dreday is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    58
    Try removing the quotes since you're doing a numeric comparisons with the > symbol and the <> symbol. You can also force the text boxes into numeric format with cInt() and account for NULL with nz()

    Example 2:
    If ((cint(nz(Me.txtEliAge,0)) > 18) Or (cint(nz(Me.txtEliLiving,0)) <> 3) Or (cint(nz(Me.txtEliERReason,0)) <> 2)) Then
    Me.txtDemEligible = "Yes"
    Else
    Me.txtDemEligible = "No"
    End If

    Hope this one works!

  11. #11
    royalrochelle is offline Novice
    Windows XP Access 2007
    Join Date
    May 2010
    Posts
    13
    Thanks so much for your help dreday. I removed the quotations and that did help a lot but I had to change some of the coding to get it to work. Instead of:

    If Me.txtEliAge > 18 Or Me.txtEliLiving <> 3 Or Me.txtEliERReason <> 2 Then
    Me.txtDemEligible = "Yes"
    Else
    Me.txtDemEligible = "No"
    End If

    I had to write:
    If Me.txtEliAge < 18 Or Me.txtEliLiving = 3 Or Me.txtEliERReason = 2 Then
    Me.txtDemEligible = "No"
    Else
    Me.txtDemEligible = "Yes"
    End If

    and it worked like a charm! Thank you so much for your help

  12. #12
    dreday's Avatar
    dreday is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    58
    Awesome, happy to help!

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

Similar Threads

  1. Iif statement with multiple criteria
    By coach32 in forum Queries
    Replies: 1
    Last Post: 09-07-2011, 01:28 AM
  2. iif statement with multiple conditions
    By ragsgold in forum Queries
    Replies: 7
    Last Post: 08-24-2011, 05:38 PM
  3. SQL statement from multiple tables
    By Backpacker in forum Queries
    Replies: 5
    Last Post: 06-17-2011, 11:22 PM
  4. multiple IF Statement
    By newtoAccess in forum Queries
    Replies: 3
    Last Post: 11-29-2010, 09:18 AM
  5. multiple iif statement NEED HELP PLZ
    By scott munkirs in forum Reports
    Replies: 1
    Last Post: 09-27-2006, 05:21 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