Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have some code in Excel 2003 I like to use to set an embedded
combobox control's records when a client opens a workbook. The problem is it works fine when I "hard code" references, but now that I'm trying to make a "generic" routine, I'm having trouble with type mismatches. The following code works: Dim cmbVintage, As ComboBox .... other Dim statements... .... stuff to set workbook... With .Worksheets("Test") Set cmbVintage = .cmbVintage '...other stuff with that worksheet... End With where .cmbVintage is an embedded ComboBox control on the "Test" Worksheet. I then go on to set a recordset object to gather the records I want to display. After that, I use the following code to put the variable in an Object array so I can use the same code to fill a number of similar controls with different recordsets: Select Case i2 .... Case 5 Set objDropDownMaintenance(1, i2) = recVintage Set objDropDownMaintenance(2, i2) = cmbVintage The following code then loads each of the combobox controls in the array: Set recTemp = objDropDownMaintenance(1, i2) With recTemp .MoveFirst .MoveLast lngRecords = .RecordCount lngFields = .Fields.Count .MoveFirst End With Set cmbTemp = objDropDownMaintenance(2, i2) With cmbTemp .ColumnCount = lngFields .Column = recTemp.GetRows(lngRecords) End With Next i2 I'd like to use a similar construct so that I can have a range on a reference worksheet that holds the target worksheets names, the names of the embedded controls on that worksheet and the recordset instructions. I can get it to reference the controls by using the following: With .Worksheets(strTargetWorksheet) strTargetCmb = strDropDownMaintenance(2, i1) Set objDropDownMaintenance(1, i1) = .OLEObjects(strTargetCmb) End With But when I then try to use the same technique: Set objTemp = objDropDownMaintenance(1, i1) Set cmbTemp = objTemp With cmbTemp .ColumnCount = lngFields .Column = recTemp.GetRows(lngRecords) End With I get an error when setting the OLEObject variable to the ComboBox variable (when in fact the type of OLEObject it is is a ComboBox). It would seem to me that the contruct is similar enough to what is happening with the Worksheets(x).comboboxname construction that works, but obviously not. Anyone have a suggestion on how to more directly reference an embedded object in order to do this? If not, any other suggestions on loading an embedded OLEObject on the fly? I've thought briefly about creating a range with the recordset results in another hidden worksheet and then setting the embedded control's ListFillRange to that, but not having used that property before I wanted to ask before going down that road. Any insights would be appreciate. Thank you, Bruce |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Visual Basic Error Run Time Error, Type Mismatch | Excel Discussion (Misc queries) | |||
runtime error 13 - type mismatch error in Excel 97 on Citrix | Excel Programming | |||
Excel 2003 - Combobox.AddItem type mismatch | Excel Programming | |||
Help: Compile error: type mismatch: array or user defined type expected | Excel Programming | |||
Befuddled with For Next Loop ------ Run - Time Error '13' Type Mismatch Error | Excel Programming |