Solved

Excel VBA combobox update problem

Posted on 2002-03-14
10
2,544 Views
Last Modified: 2009-03-19
have a form with a combobox list box that gets updated with the program. It's not...

The named range is updating properly, but the form won't... here's my bits of code:

Worksheets("1stontape").Names.Add Name:="firstlist", RefersToR1C1:="=R1C1:R" & maxrowlist + 1 & "C1"

thats for updating the name range..

the rowsource IS set to firstlist. If I manually check the range, it IS working... but my form usually don't display it.... if I play around w/it enough, I might get lucky, but...

thanks!
0
Comment
Question by:starl
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6867580
please note that there is an MSOffice Topic area, where  you should get more experts for that problem:
http://www.experts-exchange.com/jsp/qList.jsp?ta=msoffice

Now, how/when do you update your forms' combobox?

CHeers



0
 
LVL 8

Author Comment

by:starl
ID: 6868050
I know angel... but this is a VBA prob and there's no real section for VBA. Though there is some knowledge of VBA in Office I hoped to get more here.

... update the combobox... well, it reads the listing off a named range on a sheet.
0
 
LVL 44

Expert Comment

by:bruintje
ID: 6868732
Hi starl, you provided the update of the named range, but is the form loaded and updated also?

i mean is there also a load list procedure to get the values in the combobox? or is that done at design time

:O)Bruintje
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Author Comment

by:starl
ID: 6869021
*sigh* my ignorance and delving into something I don't knwo 100% is showing...

I've created a form in the editor. There is code behind that form. The part I'm having problems with is a combobox. It gets its list from a "rowsource" which, in this case, is a dynamic named range. I have other comboboxes on the form, but they are static - they show the info no problem.

Even if I restart the program and there IS info in the range, the combobox will not necessarily reflect this.

shouldn't it at least work ALL THE TIME if I restart the program? I've either done something wrong or there's a bug/error somewhere.

btw, excel 2000
0
 
LVL 44

Expert Comment

by:bruintje
ID: 6869637
Hi starl, ok i did this

-put a form in the editor
-a combox on it
-then used this code to fill the box

Private Sub UserForm_Initialize()
Dim i As Integer
  For i = 0 To 10
    ComboBox1.AddItem i * i, i
  Next i
End Sub

-instead of the values i used with i you can loop through the named range to fill the box

if you need any help on that just ask....

HTH:O)Bruintje
0
 
LVL 8

Author Comment

by:starl
ID: 6869656
ok.. the named range is "firstlist" and the size will vary with time... how to work with it??
0
 
LVL 44

Expert Comment

by:bruintje
ID: 6869724
:O) i had already pulled the plug on excel

Private Sub UserForm_Initialize()
Dim i As Integer
  For i = 0 To Worksheets(1).Range("firstlist").Count - 1
    ComboBox1.AddItem Range("firstlist").Value(i + 1, 1), i
  Next i
End Sub

HTH:O)Bruintje
0
 
LVL 12

Accepted Solution

by:
roverm earned 100 total points
ID: 6869829
You are using the worksheet name where you should have used the workbook names list...:

ActiveWorkbook.Names.Add Name:="firstlist", RefersToR1C1:="='1stontape'R1C1:R" & maxrowlist + 1 & "C1"

Also:
(But I don't know if you already did that): Refresh the combo by using:

Combo.RowSource = "firstlist"

You must do this at Form activation.

D'Mzzl!
RoverM
0
 
LVL 8

Author Comment

by:starl
ID: 6870113
Ha! thanks rover - that fixed it.. I did wonder why the namedrange had that extra line in the excel list of definitions. THANK YOU!

and I WAS missing the refresh. the last piece of the puzzle - thank you.
0
 
LVL 12

Expert Comment

by:roverm
ID: 6870571
Thanks starl! Glad I could help!

D'Mzzl!
RoverM
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question