Link to home
Start Free TrialLog in
Avatar of jstiles5
jstiles5

asked on

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
    cboContacts.AddItem
   
Loop
Close #1

Avatar of rockiroads
rockiroads
Flag of United States of America image

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

"A;B;C;D;E;F"

will show

A
B
C
D
E
F


but if two columns, it shows
A B
C D
E F

Avatar of jstiles5
jstiles5

ASKER

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.

ASKER CERTIFIED SOLUTION
Avatar of rockiroads
rockiroads
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This is Visual Basic 6.0.  I guess that's VBA?

cboContacts.AddItem
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?  

jstiles5

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.

AW
The following URL has info on adding items to ComboBoxes in VB 6.0 (as well as other versions):
http://msdn2.microsoft.com/en-us/library/fte6kbt2.aspx

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).
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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?

jstiles5
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.

AW