Consulting

Results 1 to 18 of 18

Thread: uneditable comboboxes

  1. #1
    VBAX Mentor
    Joined
    Dec 2009
    Posts
    416
    Location

    uneditable comboboxes

    good morning,

    Question:It is an possiblity to protect comboboxes, to become uneditable, but still to have the drop down list?

    thx

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Change the .Style property to fmStyleDropDownList

  3. #3
    VBAX Mentor
    Joined
    Dec 2009
    Posts
    416
    Location
    thx for answer. now if the following error:

    Could not set the Value propriety. Invalid property value. (logic because)
    ComboBox9.Value = Rng(11) .. how can I put an logical statement that can initzialized the first value from combobox list if the value is not equal or is missing

  4. #4
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Hi white_flag,

    I am afraid that your question is not making sense to me. Please attach a small example workbook with the combobox and the code as is; that is, to show how you are currently trying to add value(s) to it, and from whence the vals came.

    Thanks,

    Mark

  5. #5
    VBAX Mentor
    Joined
    Dec 2009
    Posts
    416
    Location
    correct ..mia culpa.
    Please look in attach. It talks better then me.

  6. #6
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Hi there,

    I doubt that I'll be of much help, but if I can be a little help, and one of the guys can come by and rescue us, that would be great. Here is what I observed:

    Quote Originally Posted by white_flag
    thx for answer. now if the following error:

    Could not set the Value propriety. Invalid property value. (logic because)

    ComboBox9.Value = Rng(11) ..


    I do not see the above anywhere in the code. That said, I did find where the value of ComboBox9 was (attempted) assigned to "Rng(11)".

    Presuming that you included all the code, I do not see where 'Rng()' is declared or sized?

    Quote Originally Posted by white_flag
    how can I put an logical statement that can initzialized the first value from combobox list if the value is not equal or is missing
    I am afraid that with not understanding how the array could work at this point, this part is just beyond me :-(

    I hope you get some great help, or can say whether CommandButton12 (click) runs for you if there is missing code or something that I am just not getting. The userform seems very neat to me; I really like how you have it changing languages!

    Sorry I cannot help thus far,

    Mark

  7. #7
    VBAX Mentor
    Joined
    Dec 2009
    Posts
    416
    Location
    thx, Mark

    for me I would like to put an deviation from error.
    Like: if error, initialized combobox with first value from list ..etc

  8. #8
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    I think you need to find the item in the Combo and change the ListIndex to suit

    Private Sub ListBox1_Click()
    Insul = ListBox1
        Set Rng = Rows(2).Find(Insul, LookAt:=xlWhole).resize(1)
                TextBox1.Value = Rng(1) 'name
                TextBox2.Value = Rng(2) 'diametru
                TextBox4.Value = Rng(3) 'Lenght Body
                ComboBox6.Text = Rng(4) 'Insulation Body
                ComboBox7.Value = Rng(5) 'tk Insulation Body
                TextBox9.Text = Rng(6) 'Layer Insulation Body
                ComboBox8.Text = Rng(10) 'Type Sheeting Body
    'Change here
                ComboBox9.ListIndex = LIndex(ComboBox9, Rng(11)) 'tk Sheeting Body
    '............
     
    Function LIndex(Ctrl As Control, v)
        Dim i As Long
        For i = 0 To Ctrl.ListCount
        If v = --Ctrl.List(i) Then
            LIndex = I
            Exit Function
        End If
        Next
    End Function
    Last edited by Aussiebear; 04-19-2023 at 12:08 AM. Reason: Adjusted the code tags
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  9. #9
    VBAX Mentor
    Joined
    Dec 2009
    Posts
    416
    Location
    with: If v = --Ctrl.List(i) Then I have this error: Error 13 - Type mismatch

    with: If v = Ctrl.List(i) Then I have this error: Error 381 - Could not get the list property. invalid property array index

  10. #10
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    The values in the combos and theRng(11) etc. need to be comparable.
    -- was to convert 0.6 string to numerical. You may need to play around with these to get it to work.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  11. #11
    VBAX Mentor
    Joined
    Dec 2009
    Posts
    416
    Location
    ok thx ..but before you go from this thread. I have one more question that you help me in an different thread. how can I delete the first two rows from the listbox without having an error. Like this to have an empty file without any data inserted in worksheet

  12. #12
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Read the items into an array, clear the box then add them back, omitting the first two.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  13. #13
    VBAX Mentor
    Joined
    Dec 2009
    Posts
    416
    Location
    ok ..I am so lost ..can you be more precise? I would like to fix this alone, but I can not ..

  14. #14
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Sub LoseFirst()
        Call NewList(ComboBox9, 2)
    End Sub
    
    Sub NewList(Ctrl As Control, ToLose As Long)
        Dim i As Long
        Dim arr()
        ReDim arr(Ctrl.ListCount - ToLose - 1)
        For i = 0 To Ctrl.ListCount - ToLose - 1
         arr(i) = Ctrl.List(i + ToLose)
        Next
        Ctrl.Clear
        Ctrl.List() = arr
    End Sub
    Last edited by Aussiebear; 04-19-2023 at 12:09 AM. Reason: Adjusted the code tags
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  15. #15
    VBAX Mentor
    Joined
    Dec 2009
    Posts
    416
    Location
    thx for help ..but this is to much for me.I have to search for an simple solution

  16. #16
    VBAX Mentor
    Joined
    Dec 2009
    Posts
    416
    Location
    in attachment is an simplify version ..maybe someone will help me

  17. #17
    VBAX Mentor
    Joined
    Dec 2009
    Posts
    416
    Location
    .. I would like here a bit of magic ..

  18. #18
    VBAX Mentor
    Joined
    Dec 2009
    Posts
    416
    Location
    good evening
    I need your help if it is possible.
    I change the "tactic" but I am stuck (again). I change the list box in listview. now, I do not know how to delete an filed or to edit an field and initialized an listview. I would appreciated any help. thank you (please look in attachment).

Posting Permissions

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