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

How to add the content of a variable to a ComboBox

Hello everybody,

I would like to know how do I add the content of a variable to a combobox.

I have the following code

For i = 1 to 10
ComboBox1.AddItem Data, i
Next i

Where I declared previously:
Public Data As String
Public i As Integer

When I run my code mi combo box just shows empty.

Hope someone can help me out.
Oct 29 '08 #1
7 5931
QVeen72
1,445 Expert 1GB
Hi,

You need to Initialize DATA variable somewhere (eg.. FormLoad)
are you doing that..?

Data = "My Data"

Regards
Veena
Oct 30 '08 #2
Yes, I am using the variable Data to store the content of a .txt file that is read first. Code below.

Public Data As String
Public i As Integer

Sub ImportRange()
Dim ImpRng As Range
Dim FileName As String
Dim r As Long
Dim c As Integer

Dim Char As String * 1
Set ImpRng = ActiveCell
On Error Resume Next
FileName = "C:\textfile.txt"
Open FileName For Input As #1
If Err <> 0 Then
MsgBox "Not found: " & FileName, vbCritical, "ERROR"
Exit Sub
End If
r = 0
c = 0
txt = ""
Do Until EOF(1)
Line Input #1, Data 'Here is where I store the content of the .txt file in Data
Nov 4 '08 #3
It appears you want to add 2 lots of information.
One being the variable Data, and the other being the variable I.

Combo1.additem Data & I
Nov 4 '08 #4
QVeen72
1,445 Expert 1GB
Hi,

May be your ComboBox is populated.. Click on the
"DROP DOWN ARROW" and check...

Regards
Veena
Nov 5 '08 #5
I dont understand why you would want to add a text file to a combobox?
A combobox is for listing items, not file contents.
You may be better using a listbox.
Nov 5 '08 #6
smartchap
236 100+
Dear letobale
Your code is okay. It seems it is a part of some other program. Please add following lines to your code and run it.

Me.Combo1.AddItem Data
Loop
Me.Combo1.ListIndex = 0 'so that filling of combo box is displayed.
End Sub

Private Sub Command1_Click()
ImportRange
End Sub

Private Sub Form_Load()
Me.Combo1.Clear
End Sub

If it works as per your expectations please acknowledge here.
Nov 5 '08 #7
Hey guys,

I finally got it working the last part of the code finishes with:

EplySel.ComboBox1.AddItem Data
Loop
EplySel.Show
Close #1
End Sub

Thanks you all.
Nov 5 '08 #8

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

Similar topics

4
by: Lucas Sain | last post by:
Hi, I think thta for this I have to use reflection... but I'm not shure. How can I find/get an object at runtime by looking for its name that is stored in a variable. For example: I have a...
3
by: Alonso | last post by:
Hi, I have two drop downs and the content of the second one must changed everytime the user changes the selection in the first one. Is any easy way of doing this? Thanks in advance. Alonso
11
by: simon | last post by:
hello, I have a form that has 10 dropdown lists in one section each of the dropdowns contain the same data what i'm looking to do is that when a user selects a value from one dropdown, change...
0
by: sunilrajak | last post by:
i have a combobox in one of datagrid's column.now if i selecting any one value from combobox next time it woll not be in the list of combobox.
3
daJunkCollector
by: daJunkCollector | last post by:
I have the html/javascript posted below, I imagine the fix to my problem is something simple that I am overlooking. My script is a little bit of html and javascript, and there is an embedded flash...
4
by: hhak | last post by:
Hi all, Im pretty new to C#, im trying to assign a combobox selected value to a int variable. int number; combobox has items added (1,2,3,4,...9) when i select a number from the combobox i...
7
by: billa856 | last post by:
Hi, My project is in MS Access 2002. In that I have two forms which I am using for Shipping Entry. Now First Form(ShippingAlerts) Is fillup by persons working in customer services.and the Second...
4
by: Greg (codepug | last post by:
Private Sub cboBody_KeyDown(KeyCode As Integer, SHIFT As Integer) 'Delete combobox entry if Del or Backspace key is hit. If (KeyCode = 46) Or (KeyCode = 8) Then Me.cboBody = "" End Sub I have...
2
by: ezechiel | last post by:
Hi, I have the following (limited to problem): 2 tables: software (sw_id (pk), sop_id(fk)) sop(sop_id, sop_name, sop_nr) In the form (actually a software record): - a combobox ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.