473,388 Members | 1,340 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

ComboBox For Loop

I have 10 comboboxes. i would like to run a loop that would reference each combo box and resets certain values. The comboboxes are named ComboBox1, Combobox2, ..... ComboBox10. Here is a sample of what i want. The error returned is "Sub or Function not defined".
Expand|Select|Wrap|Line Numbers
  1. Public Sub ResetValues()
  2.         For i = 1 to 10
  3.         ComboBox(i).listfillrange=""
  4.         'the code errors here where I want to call the combobox
  5.         ComboBox(i).visible = True
  6.     ....etc
  7. Next
  8. End Sub
Jul 12 '07 #1
4 1896
kadghar
1,295 Expert 1GB
I have 10 comboboxes. i would like to run a loop that would reference each combo box and resets certain values. The comboboxes are named ComboBox1, Combobox2, ..... ComboBox10. Here is a sample of what i want. The error returned is "Sub or Function not defined".
[ Public Sub ResetValues()
For i = 1 to 10
ComboBox(i).listfillrange=""
'the code errors here where I want to call the combobox
ComboBox(i).visible = True
....etc
Next
End Sub]
maybe your index starts from zero... you should try FOR i = 0 to 9
Jul 12 '07 #2
kadghar
1,295 Expert 1GB
oh, and i didnt noticed. all your combo boxes must have the same name. Lets say: ComboBoxes and you have to make an array of comboboxes with the same name but different indexes.

This is harder to do with VBA (not even sure if you can do it) but with any other version of VB you have "Index" in the properties menu.

Good Luck
Jul 12 '07 #3
thanks i'll check it out
Jul 12 '07 #4
Killer42
8,435 Expert 8TB
You have two options. If this is VB6 (or another compatible version) you should make the controls into a "control array". That is, they should all have the same name, and only differ in their Index value. That way, you can refer to them in a loop by just changing the index number, the same as an ordinary array.

If you're using VB.Net (effectively any VB version later than VB6, which is about 10 years old) control arrays are not supported any more (thanks a lot, M$!). You can get around it by using your index number to build a string, such as strControlName = "ComboBox" & Format(i), and then using this construct to access it... Me.Controls(strControlName)
Jul 12 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: rmatteson | last post by:
I am trying to figure out how to clear all items from a combobox (Access 2002). On my form, I have to comboboxes. Combobox 2 is populated with a set of child data dependent on the parent data...
8
by: Zlatko Matić | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the...
4
by: Strahimir Antoljak | last post by:
Has anyone experienced problems with a combo box SelectIndex property? Is there a limit to the number of Items for a combo box? Namely, when I set programmatically ComboBox.SelectIndex...
3
by: Nikolay Petrov | last post by:
I have a Combo box, binded to a dataset With cmbCompany .DataSource = dsSpecContact .DisplayMember = "Companies.CompanyName" .ValueMember = "Companies.CompanyID" End With What I want is to...
6
by: Sakharam Phapale | last post by:
Hi All, How to fill one ComboBox from other ComboBox control? 1) Only setting the reference does the trick but doesn't show items in control. If you see in immediate window, it shows...
3
by: Ivan V via DotNetMonster.com | last post by:
Hi All: I would like to know if I can loop my selection in a combobox. For instance, I got 8 items in a combobox, and when I selected it using the up and down arrow, it will stop in the first...
7
by: Hardik Shah | last post by:
Hi, Generaly to populate combobox , I use following command :- Combobox1.datasource = dataset.tablename combobox1.displaymember = fieldname1 combobox1.valuemember = fieldname2 As I don't...
1
by: SkyTV | last post by:
i have got 15 combo Boxs on the form they are named cbo1 - cbo15 the following works just fun strY= cbo1.Text; but i wanna learn the for loop way to do it.... i have tried many...
6
by: tbrown | last post by:
I have a combobox with items like this: {one,two,three}. The selected index is 0, so "one" appears in the combobox text. When the user drops down the list, and selects "two", for example, I...
2
by: graywolf | last post by:
Hi there, I have just started using Access 2003 in the last couple of months and have a couple of problems i would like some help with please for a project i am working on. PROBLEM 1. I have a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.