Conditional Expression in a query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • devmor
    New Member
    • Jan 2010
    • 2

    Conditional Expression in a query

    I'm so new to this, so you will have to explain every detail to me. Let's say I have field "1" that is populated with either W or B and a second field "2" that is populated with either H or S. If field 1 and 2 = W and H then "Undecided" If field 1 and 2 = B and H then "Non Ex" If field 1 and 2 = B and S then "Ex". Like I said since I'm new I will need you to explain where to place this in the query.

    Thanks!
  • ChipR
    Recognized Expert Top Contributor
    • Jul 2008
    • 1289

    #2
    This page has a section on using IIf in a query, and explains it quite fully.
    IIf Function[http://office.microsoft.com/en-us/ac...88531033.aspx]

    Comment

    • devmor
      New Member
      • Jan 2010
      • 2

      #3
      The link states that is no longer available. I have tried the if statement but it doesn't work. But of course I may not be putting it in the right place. I'm placing it in the criteria of one of the fields.

      Comment

      • thevbist
        New Member
        • Jan 2010
        • 3

        #4
        Hello there is a very simple solution. (You solved the problem asking the question, you just need to translate it into VBA code) The following code will mirror your question.

        Here's the code...
        Place a command button on your form "cmdDecisio n" and display the results in a textbox or lable. Or in the "AfterUppda te" of field 2.


        Private Sub cmdDecision_Cll ick()

        If Me.Field1 = "W" and Me.Field2 = "H" Then
        txtDecision = ""Undecided " or lblDecision = "Undecided"
        ElseIf Me.Field1 = "B" and Field2 = "H" then
        txtDecision = "NonEx" or lblDecision = "NonEx"
        ElseIf Me.Feild1 = "B" and Field2 = "S" then
        txtDecision = "Ex" or lblDecision = "Ex"
        End Sub



        Best Regards,



        Lamar Dixon, Jr.
        President
        Salient Technologies, LLC
        MobileMessageMe dia(MCubed)

        Comment

        • ChipR
          Recognized Expert Top Contributor
          • Jul 2008
          • 1289

          #5
          Click the words "IIf Function" in my previous post. It seems the forums have included the last ] in the address of the other link, so you could also click that and delete the bracket off the end.

          Comment

          Working...