Consulting

Results 1 to 14 of 14

Thread: Form's Drop or Scroll Boxes ~ HELP

  1. #1

    Form's Drop or Scroll Boxes ~ HELP

    I am trying to design a form in word. I need to make a few drop down sections or scroll bar for the Dx Coding part. I want to list all the Dx codes we use from the DSMIV, but the boxes, using them from the 'Forms tool Menu', it will only allow me to use 25 entries and I need at least 300. So I am trying to use the 'Control Form Tool Box'. I am having a hard time figuring it out. I believe I am using Office 2003

    I haven't worked in Word in many years now so I am a bit lost and need some help through making this. May I please borrow someone through this?

    Thank you,
    Ginger
    Ginger

  2. #2
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Please try not to use jargon, or abbreviations that people may not understand.

    I have absolutely NO idea what you are talking about re: "Dx codes", or "DSMIV".

    DSMIV?
    So I am trying to use the 'Control Form Tool Box'. I am having a hard time figuring it out.
    First of all....what have you tried?

    Second of all, why do you want to have 300 listed items? That is way too many. People mention needing such huge numbers, but I have yet to see any example where that is actually true. There are ways to RE-item a list with a different list, depending on the first item selected.

    I know if I saw a dropdown with 300 items listed I would refuse to use it.

    In any case, ActiveX controls (from the Controls toolbox) are populated by code. You can do this from any code module, but the easiest is the ThisDocument module. Then you can use the control's name directly.[vba]Sub Document_Open()
    Combobox1.Clear
    Combobox1.AddItem "candy"
    etc.[/vba]If you are going to populate it with a lot of items, then you most likely will use an array. Say you have built an array of names (ClientName).[vba]Sub Document_Open()
    Dim var
    For var = 0 To Ubound(ClientName)
    Combobox1.AddItem ClientName(var)
    Combobox1.ListIndex = 0
    Next
    End Sub[/vba]This would, on opening the document, populate the combobox with all the items in the array ClientName. It would display the first item in the list by default (ListIndex = 0). It is common to have the first item in the list notice text to the user. That is, the first item in the list could be: "Please select a name."

  3. #3
    VBAX Mentor OTWarrior's Avatar
    Joined
    Aug 2007
    Location
    England
    Posts
    389
    Location
    I have just fixed the 25 limit list on teh drop down form fields, here is the code, and a sample document of how it works.

    (note, the code can be pasted into a document, it is dynamically coded so all you have to do is give each drop down form field a different bookmark name, and also make sure that aonentry and aonexit macros are chosen in each dropdown.)

    btw, I would recommend using 2 step list select, ie: the drop down list (from an array) starts with group 1, group 2, then have a different array for each group, complete with an option to go back to the main list. I can generate a test example if you would like to know more.

    [vba]Public BKMName As String
    Public ResultCheck As String
    Public nGenCount As Boolean
    Public bprotected As Boolean
    Public unHighlighted As Boolean
    Public ffSelect As Word.FormField
    Public ffSelectList As Word.ListEntries
    Public ffSelectDropdown As Word.DropDown
    Public HighlightSettings As Word.Range
    Option Explicit

    Public Sub AOnEntry()
    Set HighlightSettings = Selection.Range
    If Selection.FormFields.Count = 1 Then
    'No textbox but a check- or listbox
    BKMName = Selection.FormFields(1).Name
    ResultCheck = ActiveDocument.FormFields(BKMName).Result
    Call ffGenerator
    Exit Sub
    ElseIf Selection.FormFields.Count = 0 And Selection.Bookmarks.Count > 0 Then
    BKMName = Selection.Bookmarks(Selection.Bookmarks.Count).Name
    ResultCheck = ActiveDocument.FormFields(BKMName).Result
    Call ffGenerator
    Exit Sub
    Else
    MsgBox "TOASTIE!!"
    End If
    ResultCheck = ffSelect.Result
    Call ffGenerator
    Exit Sub
    End Sub
    Public Function ffGenerator()
    On Error GoTo ErrerHandel
    Set ffSelect = ActiveDocument.FormFields(BKMName)
    Set ffSelectDropdown = ffSelect.DropDown
    Set ffSelectList = ffSelectDropdown.ListEntries
    nGenCount = False


    Dim Data As Variant
    Data = Array("This", "Works", "Rather", "Well", "Wouldn't", "You", "Say?", "..Next List...")
    Dim Data2 As Variant
    Data2 = Array("Data1", "Data2", "Data3", "Data4", "...Previous List")

    Dim i As Integer, i2 As Integer

    If ffSelect.Result = "Select an Option" Then
    Call unHighlighter
    Exit Function

    ElseIf ffSelect.Result = "..Next List..." Then

    ffSelect.Select
    With ffSelectList
    .Clear
    .Add "Select an Option"
    Application.DisplayStatusBar = True
    Application.StatusBar = "Please wait while Word rebuild the dropdown list..."
    For i2 = LBound(Data2) To UBound(Data2)
    .Add Data2(i2)
    Next i2
    End With
    ffSelectDropdown.Value = 1
    nGenCount = True

    Application.DisplayStatusBar = False
    Call Highlighter

    DoEvents
    SendKeys "%({DOWN})", True

    Call ffGenerator
    ElseIf ffSelect.Result = "...Previous List" Then


    ffSelect.Select
    With ffSelectList
    .Clear
    .Add "Select an Option"
    Application.DisplayStatusBar = True
    Application.StatusBar = "Please wait while Word rebuild the dropdown list..."
    For i = LBound(Data) To UBound(Data)
    .Add Data(i)
    Next i
    End With
    ffSelectDropdown.Value = 1
    nGenCount = True

    Application.DisplayStatusBar = False

    Call Highlighter

    DoEvents
    SendKeys "%({DOWN})", True

    Call ffGenerator
    Else
    nGenCount = False

    Call unHighlighter


    End If
    Exit Function
    ErrerHandel:
    MsgBox Err.Description, 64, Err.Number
    Exit Function

    End Function

    Public Sub AOnExit()
    Set ffSelect = ActiveDocument.FormFields(BKMName)
    If nGenCount = True Then
    Call Highlighter
    Exit Sub
    Else
    If ffSelect.Result = "...Previous List" Then
    Call ffGenerator
    Exit Sub
    ElseIf ffSelect.Result = "..Next List..." Then
    Call ffGenerator
    Exit Sub
    Else
    Call unHighlighter
    Exit Sub
    End If

    End If
    End Sub
    Public Function Highlighter()
    If ActiveDocument.ProtectionType <> wdNoProtection Then
    bprotected = True
    ActiveDocument.Unprotect Password:=""
    End If

    HighlightSettings.HighlightColorIndex = wdYellow
    unHighlighted = False

    If bprotected = True Then
    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
    End If
    End Function
    Public Function unHighlighter()
    If unHighlighted = True Then Exit Function
    If ActiveDocument.ProtectionType <> wdNoProtection Then
    bprotected = True
    ActiveDocument.Unprotect Password:=""
    End If
    HighlightSettings.HighlightColorIndex = wdNoHighlight
    unHighlighted = True

    If bprotected = True Then
    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
    End If
    End Function[/vba]

    Try the example document, and let me know if you have any questions about it. Hopefully it has solved your problem.

  4. #4

    Question

    Thank you for helping. I am not sure if I clearly understand everything that has been explained. I will work on it again this evening and over the weekend...

    I will try and clear my codes I used:

    DSMIV is a 'Bible' for Doctors, Therapists, Psychotherapists, etc...It is to help them give out the correct Diagnosis (Dx)

    I am designing a form for when they receive a new client, the forms they fill out will already have the Dx code with the code's description in a drop down field, Or in some form of a field. The Dx codes range from 200 through 300.

    Example of Dx Code:
    308.3 Acute Stress Disorder
    309.9 Adjustment Disorder Unspecified
    309.24 Adjustment Disorder With Anxiety
    296.8 Bipolar Disorder NOS
    296.56 Bipolar I Disorder, Most Recent Episode Depressed, In Full Remission
    296.5 Bipolar I Disorder, Most Recent Episode Depressed, In Partial Remission
    296.51 Bipolar I Disorder, Most Recent Episode Depressed, Mild



    I have four pages of Dx lists set up like this and I am trying to add all of them to a form field somehow with all the codes and descriptions.


    Thank you again
    Ginger

  5. #5
    VBAX Mentor OTWarrior's Avatar
    Joined
    Aug 2007
    Location
    England
    Posts
    389
    Location
    I have redone the example document with some of your information.
    Is this how you would want it to work?

    NB: if you only wanted the Dx Code in the dropdown box, but the description in a textbox elsewhere, then use:

    [vba]If ffSelect.Result = "308.3" then
    activedocument.formfields("dxDescription").result = "Acute Stress Disorder "
    else
    'here you would do an elseif and put every variable to input into the result.
    'you could do this calling from an array,
    end if
    [/vba]

    you can change the if command to a case select to increase the speed of the code if you find the speed to be slow

  6. #6
    That is perfect! I will have to review your notes closely and try this. It is my first time and I am not update with the correct coding and commands. I may be asking for more help.

    Thank you
    Ginger

  7. #7
    I am having a bit of hard time understanding how to put this together. This is all beyond me. It is perfect for what I need, but I think I am going to see what I can do in Excel. Thank you for you help
    Ginger

  8. #8
    VBAX Mentor OTWarrior's Avatar
    Joined
    Aug 2007
    Location
    England
    Posts
    389
    Location

    Smile

    it is not the easiest code (took me 3 months on and off to fix all the bugs) but here are the main areas to focus on:

    [vba] Dim Data2 As Variant
    Data2 = Array("Data1", "Data2", "Data3", "Data4", "...Previous List")

    Dim i As Integer
    [/vba]

    the sections in "" are each item you want in your list.
    i is the count to make sure the loop works correctly

    [vba] ElseIf ffSelect.Result = "..Next List..." Then

    ffSelect.Select
    With ffSelectList
    .Clear
    .Add "Select an Option"
    Application.DisplayStatusBar = True
    Application.StatusBar = "Please wait while Word rebuild the dropdown list..."
    For i2 = LBound(Data2) To UBound(Data2)
    .Add Data2(i2)
    Next i2
    End With
    ffSelectDropdown.Value = 1
    nGenCount = True

    Application.DisplayStatusBar = False
    Call Highlighter

    DoEvents
    SendKeys "%({DOWN})", True
    Call ffGenerator [/vba]

    change "..Next List..." to what value you want to change it to (eg: "305 -310") and change the data2 and i in that section to what your new name for your array is. Chnage the i to whatever you have called i (it doesn't matter what name, so long as each one is unique in each loop.

    hopefully, that is a bit more clearer for you.

  9. #9
    I understand a few parts, then I get lost in others. Maybe when I have more time I will come back to this. I would love to know how to do this correctly.

    I am going to see how it will work in excel...if it doesn't work then the doc's can refer to the DSM book themselves and type in their own Dx code...

    Thanks again for your help
    Ginger

  10. #10
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    I have just fixed the 25 limit list on teh drop down form fields,
    "fixed"? Ummm, not really. You did what I said could be done.

    Second of all, why do you want to have 300 listed items? That is way too many. People mention needing such huge numbers, but I have yet to see any example where that is actually true. There are ways to RE-item a list with a different list, depending on the first item selected.

  11. #11
    VBAX Mentor OTWarrior's Avatar
    Joined
    Aug 2007
    Location
    England
    Posts
    389
    Location
    Quote Originally Posted by fumei
    "fixed"? Ummm, not really. You did what I said could be done.
    Yours was using a combobox, mine was using a dropdown form field. Not the same (but the same idea, which I had posted about previously)

    Well...I have spent the past 3 months trying to get the full functionality to work by regenerating the list and making it automatically drop down when the list is regenerated, and no one on any forums that I had been on knew of a way to do this. All they suggested was to use multiple drop down boxes, or a userform.

    Sure people said you could clear the list and add items back, but nobody I spoke to said you could cycle the lists depending on theh selection. I have yet to see someone else's code which works just like mine.

    So yes, I would like to think that I have "fixed" the problem.

  12. #12
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    True, I did mention combobox. That was in response to the OP. If I may quote:
    So I am trying to use the 'Control Form Tool Box'.
    Which means....ummmm, combobox.

    In fact, OTWarrior, I was thinking of EXACTLY your posts, and was going to refer the OP to them.

    Further:
    [Sure people said you could clear the list and add items back, but nobody I spoke to said you could cycle the lists depending on theh selection.
    Not true at all. I have posted how to do this - with examples - two years ago.

    The difference is that you wanted to RESELECT the formfield. That, I agree was difficult, and you have come up with a solution. You are to be commended for that.

    However, relisting a formfield dropdown based on a user selection has been posted before. You did NOT "fix" that.

    Nor did you "fix" the issue of the 25 limit. Sorry, but your formfields still have a 25 limit.

    What you did - and again I do commend you on it - was relisting AND going back to the relisted formfield and dropping it down.

    But the relisting has been done before, and posted.

  13. #13
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    I also wish to add, that even WITH your solution (and a good one it is), the OP still has to do what I mentioned.

    That is, find a logic solution to breaking up the 300 items into meaningful chunks that can be displayed within the 25 limit of a formfield.

    If they really, really, do want to list 300 items....your solution is of no use to them. The formfields have a 25 item limit.

    If you read my post, I mentioned my opinion (just my opinion) that 300 items is too much for ANY dropdown, and that There are ways to RE-item a list with a different list, depending on the first item selected;

    but that (in response to the OP direct question on Controls)....

    "In any case, ActiveX controls (from the Controls toolbox).... "

  14. #14
    VBAX Mentor OTWarrior's Avatar
    Joined
    Aug 2007
    Location
    England
    Posts
    389
    Location
    GngrAmy did start off by saying:
    Quote Originally Posted by GngrAmy
    but the boxes, using them from the 'Forms tool Menu', it will only allow me to use 25 entries and I need at least 300.
    So I thought they would ideally want it in this format, not in activeX, that's all.

    I am sure the relisting has been done before (it's two lines of code to clear the list and add one value) But I have seen it used to change another drop down form field rather than the currently selected one.

    I know it is not a true fix to the 25 limit, but it is like putting tape on a broken chair leg. Sure, it is not how people would like it, but it works

    And I do agree that 300 is a rather large list of items to select, and you would most likely have to have a 3 or 4 step system to get to the specific option required.

    I can't think of a better solution with a drop down box (of any kind), other than just allowing the user to type whatever "dxcode" number they want into a text box, and to have another text box automatically generate a description based on the number.

Posting Permissions

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