Consulting

Results 1 to 6 of 6

Thread: How to make a ComboBox select a specific value when i enter the workbook ?

  1. #1

    How to make a ComboBox select a specific value when i enter the workbook ?

    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
    A. Cociorva

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Post the code, or better the workbook with details on how we can replicate the problem.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3

    Excel ComboBox Sample

    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:

    [VBA]ComboBox2.Value="-Select product name-"[/VBA]

    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 !
    Attached Files Attached Files
    A. Cociorva

  4. #4
    VBAX Mentor
    Joined
    Feb 2009
    Posts
    493
    Location
    [VBA]Private Sub Workbook_Open()
    Sheets("sheet1").ComboBox2.Value = "-Select product name-"
    End Sub

    [/VBA]

    You need to refer to the sheet in which the combobox resides.
    -----------------------------------------
    The more you learn about something the more you know you have much to learn.

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    This seems to do it

    [vba]
    Private Sub Workbook_Open()
    Worksheets("Sheet1").ComboBox2.Value = "-Select product name-"
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    It works perfectly! Thank you very much ! :-)
    A. Cociorva

Posting Permissions

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