473,386 Members | 1,602 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,386 software developers and data experts.

Give Values to Combo Box programmatically

Hello friends,
i have a situation where i have to take the values of combo box from the program. how can i do that.
Let me explain in detail...
i have a form which imports value from a excel sheet which can contain n number of worksheets in it. So when i select a particular excel i should open a combo box which get the names of all the worksheet it contains. Can any body help me out..... Thanks in advance
May 18 '07 #1
1 2419
maxamis4
295 Expert 100+
Man thats a tough request. So i need to recap for everyone:

1 Basically you just want to set your combo box equal to all the names of the excel spreadsheets inside your workbook right?

Now as far as filling out the combo box, I would recommend an array. Something like this this also includes the excel piece you requested.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Function get_spreadsheetName()
  3.  
  4. Public objapp As Excel.Application
  5. Public objbook As Excel.Workbook
  6. Public objsheet As Excel.Worksheet
  7. dim myarray as string
  8. dim i, y as integer 
  9. i = 0
  10.  
  11. 'Delcare file path where workbook is stored
  12. Filepath = FileLocation
  13.  
  14. Set objbook = Workbooks.Add(Template:=Filepath)  'Your excel spreadsheet file goes here
  15. Set objapp = objbook.Parent
  16.  
  17. Y = objapp.ActiveWorkbook.Worksheets.Count
  18.  
  19. For i = 1 To Y
  20.           Set oSheet = objapp.ActiveWorkbook.Worksheets(i)
  21.           sheetName = oSheet.name
  22.           Redim myarray(i)
  23.  
  24.                            myarray(i) = SheetName
  25.  
  26. Next i
  27.  
  28. cmbList.RowSource = "" 'clears the list inside your combo box
  29.  
  30.   For i = 1 To Y
  31.         strRowSource = strRowSource & MyArray(i) & ";" 
  32.     Next i
  33.  
  34. cmbList.RowSource = strRowSource
  35.  
  36. end function     
  37.  
Note i have not tested this but I think this is what you want. You need to study up on the Excel object library to understand how this works.

Hello friends,
i have a situation where i have to take the values of combo box from the program. how can i do that.
Let me explain in detail...
i have a form which imports value from a excel sheet which can contain n number of worksheets in it. So when i select a particular excel i should open a combo box which get the names of all the worksheet it contains. Can any body help me out..... Thanks in advance
May 18 '07 #2

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

Similar topics

3
by: google | last post by:
This is something I've done plenty of times in '97, but I can't seem to get it to work correctly in Access 2003. Say, for example, I have a form with an unbound combobox, the data source is a...
2
by: Dan Cook | last post by:
Ok... here's the scoop... I've got an unbound form with Serial Number, Building, and Room... all this is in tableA... Now I've got the form setup with building, room and serial number as combo...
6
by: Sebi | last post by:
Hello all, I'm thinking about overwriting the ListItem, so it can contain x additional values (not only one). Has anybody ever tried this? Has someone got an example (C#)? Can DropDownList...
20
by: MLH | last post by:
120 MyString = "How many copies of each letter do you need?" 150 MyVariant = InputBox(MyString, "How Many?", "3") If MyVariant = "2" Then MsgBox "MyVariant equals the string '2'" If...
9
by: Vmusic | last post by:
Hi, I'm using MS Access 2002. I have a form with a combo box built from a query that returns one column, and that one column is the bound column. How do you use VBA to programmatically change...
7
by: Ausclad | last post by:
Ok, ill try again..... It seems fairly simple. I have two combo boxes in a datagrid. The datagrid is bound to a a table in a dataset. The two combo boxes are bound to a single data table...
3
by: lister | last post by:
Hi all, If have the following combo: <select name="combo"> <option value="a">One</option> <option value="b">Two</option> <option value="c">Three</option> </select>
3
by: =?Utf-8?B?Y2RtdW5veg==?= | last post by:
I have created a sub routine to programmatically add an indefinite number of combo boxes to a form. The combo boxes are bound in code to a view for displaying the available options. This routine...
1
by: tremonti92 | last post by:
Hello.. I have a table with a field name called 'Professions'. There are many same multiple values for this field, for example, there are many records with the value 'Doctor' under this field. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.