Solved

Populating Combo Box with sequential files in Visual Basic

Posted on 2006-07-04
11
5,167 Views
Last Modified: 2013-11-25
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

0
Comment
Question by:jstiles5
  • 3
  • 3
  • 3
  • +1
11 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 17038669
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

0
 

Author Comment

by:jstiles5
ID: 17038862
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.

0
 
LVL 65

Accepted Solution

by:
rockiroads earned 50 total points
ID: 17038882
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

cboContacts.AddItem

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


0
 

Author Comment

by:jstiles5
ID: 17039177
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

0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 17039638
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
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 61

Expert Comment

by:mbizup
ID: 17039657
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).
0
 
LVL 61

Assisted Solution

by:mbizup
mbizup earned 100 total points
ID: 17039660
AW -- Sorry I didn't hit the refresh button.  My post is largely duplicating yours.
0
 
LVL 44

Assisted Solution

by:Arthur_Wood
Arthur_Wood earned 100 total points
ID: 17040056
so sweat. Just shows that 'great minds (LOL) think alike'

AW
0
 

Author Comment

by:jstiles5
ID: 17040089
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
0
 
LVL 61

Expert Comment

by:mbizup
ID: 17040160
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.
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 17042647
or else a ListView control.

AW
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now