Object doesn't support this property or method

JeffK627

Active Member
Joined
Jun 22, 2005
Messages
313
I'm getting the above error when I try to add items from a recordset to a combo box. One thing I noticed is that when I typed in "DropDown2" the autocomplete didn't capitalize it - in fact, when I typed "ThisWorkbook.Worksheets("Sheet5")." it didn't offer me any choices after the dot. The same thing happened when I tried typing 5 (without quotes) instead of "Sheet5". The reference to MS Forms 2.0 object library is added. This is in Excel 2007. Here's the code, any insight is appreciated!

Code:
Private Sub Workbook_Open()

    Dim cnt As ADODB.Connection
    Dim rst1 As ADODB.Recordset
    Dim stSQL1 As String
    
    Set cnt = openConn
    Set rst1 = New ADODB.Recordset
    stSQL1 = "SELECT fname, lname FROM TestTable1"
    
    With rst1
        .Open stSQL1, cnt 'Create the recordset.
        Set .ActiveConnection = Nothing 'Disconnect the recordset.
    End With

    While Not rst1.EOF
        With ThisWorkbook.Worksheets("Sheet5").DropDown2
          .AddItem (rst1.Fields("fname") & " " & rst1.Fields("lname"))
          rst1.MoveNext
        End With
    Wend
    
    rst1.Close
    Set rst1 = Nothing
    cnt.Close
    Set cnt = Nothing

End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
For ActiveX it would be something like this:

Code:
With ThisWorkbook.Worksheets("Sheet5").OLEObjects("DropDown2")

For Form controls it would be something like this:

Code:
With ThisWorkbook.Worksheets("Sheet5").Shapes("DropDown2")

Gary
 
Upvote 0
Thanks, Gary - actually, when I deleted it and re-inserted it as an ActiveX combo box I didn't even need the "OLEObjects" qualifier, it came up as a member of the worksheet.
 
Upvote 0

Forum statistics

Threads
1,224,503
Messages
6,179,136
Members
452,890
Latest member
Nikhil Ramesh

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