Error with user form control combo box.

mthomas57

New Member
Joined
Jan 4, 2019
Messages
17
This is Mike once again. Trying to read the value from a user form control combo box. Can anyone explain why I'm getting this error from the code below? The error occurs at "LetterID = .List(.ListIndex)". LetterID is a variant type.
Thanks in advance!

Error: Object doesn't support this property or method


Code:

Dim wk As Worksheet
Dim dd As Shape

Set wk = ThisWorkbook.Worksheets(WSName)
Set dd = wk.Shapes("Cmb_LetterID")

With dd.ControlFormat
LetterID = .List(.ListIndex)
End With
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
What do you mean by a 'user form control' combo box?

If this control is on a sheet it's either a Forms control or an ActiveX control, if it's the latter it's similar to a userform control but it's not the same.
 
Upvote 0
Your code is correct if you have a form control combo on the sheet.
Apparently you have an ActiveX control combo, then the code should be:

Code:
    With Sheets(wsname).Cmb_LetterID
        LetterID = .List(.ListIndex)
    End With
 
Upvote 0
Thanks so much for the reply. This is a Form Control drop down. There is an activeX on the same sheet because I'm trying to get one of them to work and neither one does. I'm focusing now on the Form Control to get it to work. Just cant read the value from the drop down. It gives me the error "Object doesn't support this property or method" at line LetterID = .List(.ListIndex).

Thanks again for your help
Mike
 
Upvote 0
I did the test with both codes and it works

Code:
Sub test1()
'Form Control
    wsname = "Hoja9"
    Dim wk As Worksheet
    Dim dd As Shape
    
    Set wk = ThisWorkbook.Worksheets(wsname)
    Set dd = wk.Shapes("Cmb_LetterID")
    
    With dd.ControlFormat
        LetterID = .List(.ListIndex)
    End With
End Sub

'

Code:
Sub test2()
'ActiveX Control
    wsname = "Hoja8"
    With Sheets(wsname).Cmb_LetterID
        LetterID = .List(.ListIndex)
    End With
End Sub

See my examples:
https://www.dropbox.com/s/pc24s6tz3ud34qo/combos.xlsm?dl=0
 
Upvote 0
Interesting indeed. I did find a solution that is working for me. Basically I had to Dim dd as an Object. Thanks again so much for your help!

Code:

Dim ws As Worksheet
Dim dd As Object

WSName = ActiveSheet.Name
Set ws = ThisWorkbook.Worksheets(WSName)
Set dd = ws.DropDowns("Cmb_LetterID")
LetterID = dd.List(dd.ListIndex)
 
Upvote 0
By the way, in vba it is not necessary to declare variables, if they are declared they must be done correctly since they can produce errors.

Im glad to help you!:)
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top