Consulting

Results 1 to 6 of 6

Thread: Solved: If and ElseIf Statement

  1. #1

    Solved: If and ElseIf Statement

    Hello, I'm having trouble getting this code to work the way I want it to. Here is the code with comments as to what I am trying to accomplish. I'm sure that I have something out of place. I know I do, I just do not know how to solve it.

    Thanks for any help.

    [VBA]'If ComboBox A = Won, If CheckBox A = Checked and If TextBox A < 200 then xMsg = then xMsg = Ver 1 OR
    'If TextBox A > 200 then xMsg = Ver 2
    If CbxBenexx.Value = "Won" Then
    If cb401k.Value = True Then
    If tbEECount < 200 Then
    xMsg = "Benexx Ver 1"
    ElseIf tbEECount > 200 Then
    xMsg = "Benexx Ver 2"

    'If ComboBox A = None, If CheckBox A = Checked and If TextBox A < 200 then xMsg = then xMsg = Ver 1 OR
    'If TextBox A > 200 then xMsg = Ver 2
    ElseIf CbxBenexx.Value = "None" Then
    If cb401k.Value = True Then
    If tbEECount < 200 Then
    xMsg = "Benexx Ver 1"
    ElseIf tbEECount > 200 Then
    xMsg = "Benexx Ver 2"
    End If
    End If
    End If
    End If
    End If

    resString = resString & Delimiter & xMsg[/VBA]
    Last edited by Bob Phillips; 08-20-2012 at 12:05 AM. Reason: Added VBA tags

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    "Air code" warning, not tested...

    [VBA]If CbxBenexx.Value = "Won" Then
    If cb401k.Value = True And tbEECount < 200 Then
    xMsg = "Benexx Ver 1"
    ElseIf cb401k.Value = True And tbEECount >= 200 Then
    xMsg = "Benexx Ver 2"
    End If

    ElseIf CbxBenexx.Value = "None" Then

    If cb401k.Value = True And tbEECount < 200 Then
    xMsg = "Benexx Ver 1"
    ElseIf cb401k.Value = True And tbEECount >= 200 Then
    xMsg = "Benexx Ver 2"
    End If
    End If

    resString = resString & Delimiter & xMsg[/VBA]
    Is that closer?

    Mark

  3. #3
    Yes much closer. At least I do not get an error now.

    I'll test it much more in-depth on Monday.

    It needs a little adjusting. I think I can figure it out. If not I'll post back on here with more details.

    Thanks your your time!

    Mike

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Can't you reduce it to

    [VBA]If (CbxBenexx.Value = "Won" Or CbxBenexx.Value = "None") And cb401k.Value Then
    If Val(tbEECount.Text) < 200 Then
    xMsg = "Benexx Ver 1"
    Else
    xMsg = "Benexx Ver 2"
    End If
    End If

    resString = resString & Delimiter & xMsg
    [/VBA]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    or to

    [VBA]
    resString = resString & Delimiter & "Benexx Ver " & iif(Val(tbEECount.Text) < 200,1,2)
    [/VBA]

  6. #6
    I could not get either GOT's or xld's code to work like I wanted it. So after reviewing and playing around a bit with the code I realized that I did not care about the value of cb104k. All I really needed was the values of CbxBenexx and tbEECount.

    Thanks for everyones input!

    After it was all said and done here is code I ended up with:

    [VBA]If CbxBenexx.Value = "None" Then
    If Val(tbEECount.Text) < 200 Then
    xMsg = "Benexx Ver 1"
    Else
    xMsg = "Benexx Ver 2"
    End If
    End If

    resString = resString & Delimiter & xMsg[/VBA]
    Last edited by Bob Phillips; 08-20-2012 at 09:30 AM. Reason: Added VBA tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •