Populating Combo Box with sequential files in Visual Basic

I'm trying to populate a combo box with data from sequential files in Visual Basic, using AddItem method.  Visual Basic won't let me
put more than one field in the combo box.  My code follows below:

I tied every way I could envision to add more fields to the "cboContacts.AddItem" statement.
VB rejected everything I tried.  How can I get more fields in the box?

After getting the fields I want in the combo box I want to add text boxes to the form that refer to the elements of the combo box.  (I can do
this in Access by referring to Column(0), Column(1), column(2), etc.  How can I do these two things?
The field names have been

'Open file for Input and Load
Open pstrFile For Input As #1
Do Until EOF(1) = True
    Input #1, pstrName, pstrStreetAddress, pstrCity, pstrState, pstrZip, _
        pstrHomePhone, pstrWorkPhone, pstrExtension, pstrCell, pstrEmail
Close #1

Who is Participating?
rockiroadsConnect With a Mentor Commented:
Oh, its VB and not VBA then
I know sometimes people post here but refer to VBA as VB

ok, in your sample code, is this the full line or is it just an example


cos if its your full line, u need the text value to add afterwards, if an example then just ignore

In Access, u have to set the RowSourceType as a Value List then set the RowSource as a semicolon delimited string

e.g. a column of one, with values


will show


but if two columns, it shows

jstiles5Author Commented:
I have never had this problem in Access.  It works fine with all settings in the default setting.    In Visual Basic, I have about 10 fields I would like
to get into the Combo Box if possible.  Then I would like to have text boxes refer to the fields which are in the combo box.  I still don't understand
how to make this happen.  I'm not very experienced with VB.  I have done it in Access.

Thanks for your comments.

Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

jstiles5Author Commented:
This is Visual Basic 6.0.  I guess that's VBA?

This is the full line.  I have tried to add any number of other stuff including a reference to text to it and nothing will run.  
Unfortunately I don't have an example of syntax to look at and "help" is, as often, not too helpful.  I tried to use the example
given by the intelliicoding? and to follow it but it wouldn't run either so I've been squashed every time I tried to do anything
other than what I have.  So thanks for your help and your interest.

So what would the statment look like?  


The combo box control that ships with VB 6 is NOT (repeat NOT) the same control that is built into Access.  The VB 6 Combo Box control does not permit you to have multi-column values, the way the Access combo box control does.  The were third party controls that permitted this, but since VB6 has been deprecated by Microsoft, those ActiveX controls are very difficult to find, comercially.

The following URL has info on adding items to ComboBoxes in VB 6.0 (as well as other versions):

The syntax needed according to that is:
cboContacts.AddItem "Your Item To Be Added"            '** this is either text in quotes, or a string variable.

Also, the standard combobox in Visual Basic does not support multiple columns like comboboxes in Access do.  You would either need to use another standard control, such as a datagrid, or use a third-party combo box designed to handle multiple columns (try googling "vb 6.0 multiple columns in combobox" for more information).
mbizupConnect With a Mentor Commented:
AW -- Sorry I didn't hit the refresh button.  My post is largely duplicating yours.
Arthur_WoodConnect With a Mentor Commented:
so sweat. Just shows that 'great minds (LOL) think alike'

jstiles5Author Commented:
I tried to increase points but the system took it away.  Sorry, I tried.  Thanks for the help.

I'm trying to create a simple, stand alone quick look-up of telephone numbers for receptionists, etc. with my name on
it so I can keep it in front of them.  The combo box would have made it easy if it had worked.  Any suggestions?

I'd suggest using a datagrid.  The steps (very sketchily) are:
1. Populate the datagrid with the required data
2. Add functionality, either through an edit column, or through the SelectedIndexChanged event for edits and updates
3. Use the footer of the datagrid, or a seperate form to allow additions to your list.
4. If your list is long, add command buttons to control the paging of your datagrid (ie: viewing A-C, D-F, G-K, etc...)

I realize that is hopelessly general... I have done this using ASP.Net/ VB.Net and it works and looks great.  However, the implementation of those steps in VB 6.0 would be quite different.  You might do better asking the fine folks in the VB topic area for assistance, since VB (not Access) is the tool for your user interface.   Break the question up into several steps (someone might even suggest using something other than a Datagrid as a better alternative), since this will be more tedious than using Access.
or else a ListView control.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.