Wrox Programmer Forums
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 2nd, 2004, 01:55 PM
Authorized User
 
Join Date: Jun 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default New to ComboBox

Hi:

I have a ComboBox called cboList. My code follows:

-------------------------------------------------------
1
-------------------------------------------------------
Private Sub cboList_DropButtonClick()
  Dim arr(1 To 2) As String
  Dim i As Integer

  arr(1) = "Test1"
  arr(2) = "Test2"

  cboPortfolioList.Clear

  For i = 1 To 2
    cboPortfolioList.AddItem arr(i)
  Next i

End Sub

The DropButtonClick function works just fine. But when I tried to select a value, I could't see the selected value in the ComboBox. I tried to use Application.ScreenUpdating = True to see what's happening. It seemed that my selected value appeared for 1/1000 sec and then dissapeared.

I also tried the following, which also failed:

-------------------------------------------------------
2
------------------------------------------------------
Private Sub cboList_Change()
  Select Case cboList.Value
  Case 0
    cboList.Text = "Test1"
  Case 1
    cboList.Text = "Test2"
  End Select
End Sub

Following code works:
---------------------------------------------------------
3
--------------------------------------------------------

Private Sub cboList_Change()
  Select Case cboList.Value
  Case 0
    cboList.Text = "Test 1"
  Case 1
    cboList.Text = "Test 2"
  End Select
End Sub

NOTICE the string values in the third code are with space, i.e. "Test 1" and not "Test1". In another word, the text property works if the assigned value is not equal to the value property.


My question is how can I make my selection permanently visible? Shouldn't the ComboBox control automatically change its value to user's selection? and why does the text property only work if its value is different from the value property?


Regards,
Adrian T
 
Old August 16th, 2004, 02:59 AM
Authorized User
 
Join Date: Aug 2004
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You should initialise your combobox using the form
Private Sub UserForm_Initialize()
event.

We use the *Change* event to extract/use the selection to do something.


-----------------------
Regards BrianB
Most problems occur from starting at the wrong place.
Use a cup of coffee to make Windows run faster.
It is easy until you know how.
 
Old August 23rd, 2004, 10:16 AM
Authorized User
 
Join Date: Aug 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am having the same problem except that my controls are the Active X ones and the value only disappers when I bring up the excel sheet through a hyperlink to it. The value disappers as well as checkboxs etc do not work. But when I use it through my local machine it works fine. Also all values for the box are loaded on the bringing up of the user form and NOT ON CHANGE.

Any ideas folks?

Thank you
 
Old August 23rd, 2004, 12:32 PM
Authorized User
 
Join Date: Aug 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Solution to this problem was to turn on the option in file types for excel to open in same application so it would open fine in IE and still have the controls work. You might also have to re-register the app with running excel.exe /regserver to get rid of excel opening the workbook twice but thats it and it will work fine.

Billy Woodhams






Similar Threads
Thread Thread Starter Forum Replies Last Post
combobox nagarajuballa Java GUI 0 August 13th, 2008 03:49 AM
Filling Combobox with value from other Combobox ayazhoda Access VBA 6 June 5th, 2007 04:58 AM
Combobox stepdev Excel VBA 1 May 22nd, 2006 02:50 PM
combobox HenkRog VS.NET 2002/2003 2 March 17th, 2004 01:07 PM
ComboBox: HELP! ;) ashley_y ADO.NET 1 December 29th, 2003 10:44 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.