• Need to list lines from ComboBox (English/Word97/SR2)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Need to list lines from ComboBox (English/Word97/SR2)

    Author
    Topic
    #386338

    Hi. The only way that I can figure out to do it will take lines and lines of code, and I am hoping that there is an easier way.

    I have a UserForm set up with one box a drop-down combo list for the users to select which practice code they are opening this file under. There are 85 of these lines (if I start counting at 0) and each one is added with an additem code. (i.e. .AddItem “CORP 10 Corporate – Incorporation”).

    I have grouped all 85 practice codes so that if any of the lines 0-21 are chosen, then the practice group is =1, lines 22-29 = 7, etc.

    I need to have the macro fill in the Practice Group automatically into a box on the Word form based on which practice code the user chooses. However, the only way I can actually get this to work is by using If … Then statements on each individual line. For example: If cboPracticeCode = “CORP 10 Corporate – Incorporation” then
    strPracGroup=1
    and do this for each line.

    Is there any way for me to specify to the macro that if lines 0-21 are selected by the user, then strPracGroup=1? I have tried value and list, but I haven’t got either one to work. Hopefully, there is an easier way.

    I hope this makes sense. Any input would be appreciated.

    Viewing 2 reply threads
    Author
    Replies
    • #670034

      Instead of using an “equal to” can you use a “less than or equal to” and qualify by the line number rather than the text of the item?

      Just a thought off the top of my head.

      Kim

    • #670043

      (Edited by Kevin on 21-Apr-03 09:46. Bryan beat me to the Post button, making my post a bit redundant..)

      How about

      if cboPracCode.ListIndex < 22 then

      elseif cboPracCode.ListIndex < 44 then

      elseif cboPracCode.ListIndex < 66 then
      else bla bLA

      A select statement might look nicer in a print out:

      Select Case cboPracCode.ListIndex
      Case 0 to 21
      case 22 to 44
      case 45 to 66 etc. etc…
      End Select

      fyi: The above is air code, use with intellisense…

    • #670041

      (Edited by carbonnb on 21-Apr-03 12:48. to fix a small mistake in the code)

      It sounds like you will be better off with a Select Case structure

      Select Case cboPracticeCodeComboBox.ListIndex 
        Case 0 to 21
          PracticeGroup = 1
        Case 22 to 29
          PracticeGroup = 7
      '....
      'These are just made up numbers, yours will be different
        Case 75 to 83
          PracticeGroup = 12
        Else
          'This will catch anything not caught by the above conditions.
           PracticeGroup = 18
      End Select
      
    Viewing 2 reply threads
    Reply To: Need to list lines from ComboBox (English/Word97/SR2)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: