PDA

View Full Version : How to make a ComboBox select a specific value when i enter the workbook ?



AlexCociorva
04-19-2012, 01:34 AM
Hi all,
I recently had a problem which put me in difficulty. I am developing an vbaexcel-based application which needs to select a specific ComboBox value from it's range each time I pass a start Form and enter the sheet (after introducing the username). The major problem is that my ComboBox won't receive that value in any way possible (i receive an error each time I write ComboBox.Value in the form, and/or workbook). I would be thankfull if any of you could help me on this one! I am looking forward for any suggestion at this problem !

Regards,
Alex

Bob Phillips
04-19-2012, 01:55 AM
Post the code, or better the workbook with details on how we can replicate the problem.

AlexCociorva
04-19-2012, 04:30 AM
Hello !

I have extracted a part from the main project and saved it into a separate excel file for explaining the problem. The attached file contains the ComboBox (in sheet1) with it's range values (from sheet2). In the VBA section (in workbook actions) I wrote the following code line:

ComboBox2.Value="-Select product name-"

The problem is that i receive the following object error each time I open the workbook: "Runtime error 424: Object required". The same message i receive if i write the same code in the back of a form or different procedure, although is it valid in 'ComboBox2.Change' procedure.

Thank you !

BrianMH
04-19-2012, 04:58 AM
Private Sub Workbook_Open()
Sheets("sheet1").ComboBox2.Value = "-Select product name-"
End Sub



You need to refer to the sheet in which the combobox resides.

Bob Phillips
04-19-2012, 05:00 AM
This seems to do it


Private Sub Workbook_Open()
Worksheets("Sheet1").ComboBox2.Value = "-Select product name-"
End Sub

AlexCociorva
04-19-2012, 05:56 AM
It works perfectly! Thank you very much ! :-)