Solved

Populating Combo Box with sequential files in Visual Basic

Posted on 2006-07-04
11
5,168 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Send a .ZPL file to a network printer from Access 8 53
I need to be able to get MAX(date)-1 from table. 4 27
Query design issue 2 24
error 3022 in access vba 3 8
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

867 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

15 Experts available now in Live!

Get 1:1 Help Now